當前位置: 首頁>>代碼示例>>Golang>>正文


Golang parser.TypedExpr類代碼示例

本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/sql/parser.TypedExpr的典型用法代碼示例。如果您正苦於以下問題:Golang TypedExpr類的具體用法?Golang TypedExpr怎麽用?Golang TypedExpr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TypedExpr類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: distSQLExpression

// The distsql Expression uses the placeholder syntax (@1, @2, @3..) to
// refer to columns. We format the expression using an IndexedVar formatting
// interceptor. A columnMap can optionally be used to remap the indices.
func distSQLExpression(expr parser.TypedExpr, columnMap []int) distsql.Expression {
	if expr == nil {
		return distsql.Expression{}
	}
	var f parser.FmtFlags
	if columnMap == nil {
		f = parser.FmtIndexedVarFormat(
			func(buf *bytes.Buffer, _ parser.FmtFlags, _ parser.IndexedVarContainer, idx int) {
				fmt.Fprintf(buf, "@%d", idx+1)
			},
		)
	} else {
		f = parser.FmtIndexedVarFormat(
			func(buf *bytes.Buffer, _ parser.FmtFlags, _ parser.IndexedVarContainer, idx int) {
				remappedIdx := columnMap[idx]
				if remappedIdx < 0 {
					panic(fmt.Sprintf("unmapped index %d", idx))
				}
				fmt.Fprintf(buf, "@%d", remappedIdx+1)
			},
		)
	}
	var buf bytes.Buffer
	expr.Format(&buf, f)
	return distsql.Expression{Expr: buf.String()}
}
開發者ID:jmptrader,項目名稱:cockroach,代碼行數:29,代碼來源:distsql_physical_planner.go

示例2: checkEquivExpr

func checkEquivExpr(a, b parser.TypedExpr, sel *selectNode) error {
	// The expressions above only use the values 1 and 2. Verify that the
	// simplified expressions evaluate to the same value as the original
	// expression for interesting values.
	for _, v := range []parser.Datum{
		parser.NewDInt(0),
		parser.NewDInt(1),
		parser.NewDInt(2),
		parser.NewDInt(3),
		parser.DNull,
	} {
		for i := range sel.curSourceRow {
			sel.curSourceRow[i] = v
		}
		ctx := &parser.EvalContext{}
		da, err := a.Eval(ctx)
		if err != nil {
			return fmt.Errorf("%s: %v", a, err)
		}
		db, err := b.Eval(ctx)
		if err != nil {
			return fmt.Errorf("%s: %v", b, err)
		}
		// This is tricky: we don't require the expressions to produce identical
		// results, but to either both return true or both return not true (either
		// false or NULL).
		if (da == parser.DBoolTrue) != (db == parser.DBoolTrue) {
			return fmt.Errorf("%s: %s: expected %s, but found %s", a, v, da, db)
		}
	}
	return nil
}
開發者ID:knz,項目名稱:cockroach,代碼行數:32,代碼來源:analyze_test.go

示例3: RunFilter

// RunFilter runs a filter expression and returns whether the filter passes.
func RunFilter(filter parser.TypedExpr, evalCtx *parser.EvalContext) (bool, error) {
	if filter == nil {
		return true, nil
	}

	d, err := filter.Eval(evalCtx)
	if err != nil {
		return false, err
	}

	return d != parser.DNull && bool(*d.(*parser.DBool)), nil
}
開發者ID:knz,項目名稱:cockroach,代碼行數:13,代碼來源:expr_filter.go

示例4: distSQLExpression

// The distsqlrun Expression uses the placeholder syntax (@1, @2, @3..) to
// refer to columns. We format the expression using the IndexedVar and StarDatum
// formatting interceptors. A columnMap can optionally be used to remap the
// indices.
func distSQLExpression(expr parser.TypedExpr, columnMap []int) distsqlrun.Expression {
	if expr == nil {
		return distsqlrun.Expression{}
	}

	// TODO(irfansharif): currently there’s no nice way to “compose” FmtFlags
	// out of multiple FmtFlag‘s (this unit does not exist today).
	// By introducing such composability, the flags below can be constructed
	// once and reused for subsequent calls. Additionally the construction of
	// the flags would not need to inspect expression type.
	var f parser.FmtFlags
	switch expr.(type) {
	case *parser.StarDatum:
		// By default parser.StarDatum is rendered as a DInt(0), but formatting
		// this as 0 we can replicate this behavior in distsqlrun.
		f = parser.FmtStarDatumFormat(
			func(buf *bytes.Buffer, _ parser.FmtFlags) {
				fmt.Fprintf(buf, "0")
			},
		)
	default:
		if columnMap == nil {
			f = parser.FmtIndexedVarFormat(
				func(buf *bytes.Buffer, _ parser.FmtFlags, _ parser.IndexedVarContainer, idx int) {
					fmt.Fprintf(buf, "@%d", idx+1)
				},
			)
		} else {
			f = parser.FmtIndexedVarFormat(
				func(buf *bytes.Buffer, _ parser.FmtFlags, _ parser.IndexedVarContainer, idx int) {
					remappedIdx := columnMap[idx]
					if remappedIdx < 0 {
						panic(fmt.Sprintf("unmapped index %d", idx))
					}
					fmt.Fprintf(buf, "@%d", remappedIdx+1)
				},
			)
		}
	}
	var buf bytes.Buffer
	expr.Format(&buf, f)
	return distsqlrun.Expression{Expr: buf.String()}
}
開發者ID:EvilMcJerkface,項目名稱:cockroach,代碼行數:47,代碼來源:distsql_physical_planner.go


注:本文中的github.com/cockroachdb/cockroach/pkg/sql/parser.TypedExpr類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。