当前位置: 首页>>代码示例>>Golang>>正文


Golang TypedExpr.Format方法代码示例

本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/sql/parser.TypedExpr.Format方法的典型用法代码示例。如果您正苦于以下问题:Golang TypedExpr.Format方法的具体用法?Golang TypedExpr.Format怎么用?Golang TypedExpr.Format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cockroachdb/cockroach/pkg/sql/parser.TypedExpr的用法示例。


在下文中一共展示了TypedExpr.Format方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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.Format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。