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


Golang parser.AsStringWithFlags函數代碼示例

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


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

示例1: ExplainTypes

func (s *selectNode) ExplainTypes(regTypes func(string, string)) {
	if s.filter != nil {
		regTypes("filter", parser.AsStringWithFlags(s.filter, parser.FmtShowTypes))
	}
	for i, rexpr := range s.render {
		regTypes(fmt.Sprintf("render %d", i), parser.AsStringWithFlags(rexpr, parser.FmtShowTypes))
	}
}
開發者ID:BramGruneir,項目名稱:cockroach,代碼行數:8,代碼來源:select.go

示例2: ExplainTypes

func (n *limitNode) ExplainTypes(regTypes func(string, string)) {
	if n.countExpr != nil {
		regTypes("count", parser.AsStringWithFlags(n.countExpr, parser.FmtShowTypes))
	}
	if n.offsetExpr != nil {
		regTypes("offset", parser.AsStringWithFlags(n.offsetExpr, parser.FmtShowTypes))
	}
}
開發者ID:veteranlu,項目名稱:cockroach,代碼行數:8,代碼來源:limit.go

示例3: ExplainTypes

func (n *insertNode) ExplainTypes(regTypes func(string, string)) {
	for i, dexpr := range n.defaultExprs {
		regTypes(fmt.Sprintf("default %d", i), parser.AsStringWithFlags(dexpr, parser.FmtShowTypes))
	}
	for i, cexpr := range n.checkHelper.exprs {
		regTypes(fmt.Sprintf("check %d", i), parser.AsStringWithFlags(cexpr, parser.FmtShowTypes))
	}
	cols := n.rh.columns
	for i, rexpr := range n.rh.exprs {
		regTypes(fmt.Sprintf("returning %s", cols[i].Name), parser.AsStringWithFlags(rexpr, parser.FmtShowTypes))
	}
}
開發者ID:hvaara,項目名稱:cockroach,代碼行數:12,代碼來源:insert.go

示例4: explain

// explain extract information from planNodes and produces the EXPLAIN
// output via the makeRow callback in the explainer.
func (e *explainer) explain(plan planNode) {
	if e.err != nil {
		return
	}

	name, description, children := plan.ExplainPlan(e.showMetadata)

	if name == "select" && !e.showSelectTop {
		e.explain(children[len(children)-1])
		return
	}

	e.node(name, description, plan)

	if e.showExprs {
		plan.explainExprs(func(elt string, expr parser.Expr) {
			if e.err != nil {
				return
			}
			if expr != nil {
				e.attr(name, elt, parser.AsStringWithFlags(expr, e.fmtFlags))
			}
		})
	}

	for _, child := range children {
		e.subnode(child)
	}
}
開發者ID:EvilMcJerkface,項目名稱:cockroach,代碼行數:31,代碼來源:explain_plan.go

示例5: addOrMergeRenders

// addOrMergeRenders adds the given result columns to the select
// render list and returns their column indices. If an expression is
// already rendered, and the reuse flag is true, no new render is
// added and the index of the existing column is returned instead.
func (s *selectNode) addOrMergeRenders(
	cols ResultColumns, exprs []parser.TypedExpr, reuseExistingRender bool,
) (colIdxs []int) {
	colIdxs = make([]int, len(cols))
	for i := range cols {
		index := -1

		if reuseExistingRender {
			// Now, try to find an equivalent render. We use the syntax
			// representation as approximation of equivalence.  At this
			// point the expressions must have underwent name resolution
			// already so that comparison occurs after replacing column names
			// to IndexedVars.
			exprStr := parser.AsStringWithFlags(exprs[i], parser.FmtSymbolicVars)
			for j := range s.render {
				if s.isRenderEquivalent(exprStr, j) {
					index = j
					break
				}
			}
		}

		if index == -1 {
			index = len(s.render)
			s.addRenderColumn(exprs[i], cols[i])
		}
		colIdxs[i] = index
	}

	return colIdxs
}
開發者ID:BramGruneir,項目名稱:cockroach,代碼行數:35,代碼來源:targets.go

示例6: ExplainTypes

func (u *updateNode) ExplainTypes(regTypes func(string, string)) {
	cols := u.rh.columns
	for i, rexpr := range u.rh.exprs {
		regTypes(fmt.Sprintf("returning %s", cols[i].Name), parser.AsStringWithFlags(rexpr, parser.FmtShowTypes))
	}
}
開發者ID:knz,項目名稱:cockroach,代碼行數:6,代碼來源:update.go

示例7: orderBy


//.........這裏部分代碼省略.........

			if c, ok := v.(*parser.ColumnItem); ok && c.TableName.Table() == "" {
				// Look for an output column that matches the name. This
				// handles cases like:
				//
				//   SELECT a AS b FROM t ORDER BY b
				target := c.ColumnName.Normalize()
				for j, col := range columns {
					if parser.ReNormalizeName(col.Name) == target {
						index = j
						break
					}
				}
			}
		}

		if s != nil {
			// Try to optimize constant sorts. For this we need to resolve
			// names to IndexedVars then see if there were any vars
			// substituted.
			sortExpr := expr
			if index != -1 {
				// We found a render above, so fetch it. This is needed
				// because if the sort expression is a reference to a render
				// alias, resolveNames below would be incorrect.
				sortExpr = s.render[index]
			}
			resolved, hasVars, err := p.resolveNames(sortExpr, s.sourceInfo, s.ivarHelper)
			if err != nil {
				return nil, err
			}
			if !hasVars {
				// No sorting needed!
				continue
			}

			// Now, try to find an equivalent render. We use the syntax
			// representation as approximation of equivalence.
			// We also use the expression after name resolution so
			// that comparison occurs after replacing ordinal references
			// to IndexedVars.
			if index == -1 {
				exprStr := parser.AsStringWithFlags(resolved, parser.FmtSymbolicVars)
				for j, render := range s.render {
					if parser.AsStringWithFlags(render, parser.FmtSymbolicVars) == exprStr {
						index = j
						break
					}
				}
			}
		}

		// Finally, if we haven't found anything so far, we really
		// need a new render.
		// TODO(knz/dan) currently this is only possible for selectNode.
		// If we are dealing with a UNION or something else we would need
		// to fabricate an intermediate selectNode to add the new render.
		if index == -1 && s != nil {
			// We need to add a new render, but let's be careful: if there's
			// a star in there, we're really adding multiple columns. These
			// all become sort columns! And if no columns are expanded, then
			// no columns become sort keys.
			nextRenderIdx := len(s.render)

			// TODO(knz) the optimizations above which reuse existing
			// renders and skip ordering for constant expressions are not
			// applied by addRender(). In other words, "ORDER BY foo.*" will
			// not be optimized as well as "ORDER BY foo.x, foo.y".  We
			// could do this either here or as a separate later
			// optimization.
			if err := s.addRender(parser.SelectExpr{Expr: expr}, nil); err != nil {
				return nil, err
			}

			for extraIdx := nextRenderIdx; extraIdx < len(s.render)-1; extraIdx++ {
				// If more than 1 column were expanded, turn them into sort columns too.
				// Except the last one, which will be added below.
				ordering = append(ordering,
					sqlbase.ColumnOrderInfo{ColIdx: extraIdx, Direction: direction})
			}
			if len(s.render) == nextRenderIdx {
				// Nothing was expanded! So there is no order here.
				continue
			}
			index = len(s.render) - 1
		}

		if index == -1 {
			return nil, errors.Errorf("column %s does not exist", expr)
		}
		ordering = append(ordering,
			sqlbase.ColumnOrderInfo{ColIdx: index, Direction: direction})
	}

	if ordering == nil {
		// All the sort expressions are constant. Simply drop the sort node.
		return nil, nil
	}
	return &sortNode{ctx: p.ctx(), p: p, columns: columns, ordering: ordering}, nil
}
開發者ID:veteranlu,項目名稱:cockroach,代碼行數:101,代碼來源:sort.go

示例8: ExplainTypes

// ExplainTypes implements the planNode interface.
func (n *joinNode) ExplainTypes(regTypes func(string, string)) {
	if n.pred.filter != nil {
		regTypes("filter", parser.AsStringWithFlags(n.pred.filter, parser.FmtShowTypes))
	}
}
開發者ID:maxlang,項目名稱:cockroach,代碼行數:6,代碼來源:join.go

示例9: TestCopyRandom

// TestCopyRandom inserts 100 random rows using COPY and ensures the SELECT'd
// data is the same.
func TestCopyRandom(t *testing.T) {
	defer leaktest.AfterTest(t)()

	params, _ := createTestServerParams()
	s, db, _ := serverutils.StartServer(t, params)
	defer s.Stopper().Stop()

	if _, err := db.Exec(`
		CREATE DATABASE d;
		CREATE TABLE IF NOT EXISTS d.t (
			id INT PRIMARY KEY,
			n INTERVAL,
			o BOOL,
			i INT,
			f FLOAT,
			e DECIMAL,
			t TIMESTAMP,
			s STRING,
			b BYTES,
			tz TIMESTAMP WITH TIME ZONE
		);
	`); err != nil {
		t.Fatal(err)
	}

	txn, err := db.Begin()
	if err != nil {
		t.Fatal(err)
	}

	stmt, err := txn.Prepare(pq.CopyInSchema("d", "t", "id", "n", "o", "i", "f", "e", "t", "s", "b", "tz"))
	if err != nil {
		t.Fatal(err)
	}

	rng := rand.New(rand.NewSource(0))
	types := []sqlbase.ColumnType_Kind{
		sqlbase.ColumnType_BOOL,
		sqlbase.ColumnType_INT,
		sqlbase.ColumnType_FLOAT,
		sqlbase.ColumnType_DECIMAL,
		sqlbase.ColumnType_TIMESTAMP,
		sqlbase.ColumnType_STRING,
		sqlbase.ColumnType_BYTES,
		sqlbase.ColumnType_TIMESTAMPTZ,
	}

	var inputs [][]interface{}

	for i := 0; i < 100; i++ {
		row := make([]interface{}, len(types)+2)
		row[0] = strconv.Itoa(i)
		row[1] = time.Duration(rng.Int63()).String()
		for j, t := range types {
			d := sqlbase.RandDatum(rng, sqlbase.ColumnType{Kind: t}, false)
			ds := parser.AsStringWithFlags(d, parser.FmtBareStrings)
			switch t {
			case sqlbase.ColumnType_DECIMAL:
				// Trailing 0s aren't represented below, so truncate here.
				ds = strings.TrimRight(ds, "0")
			}
			row[j+2] = ds
		}
		_, err = stmt.Exec(row...)
		if err != nil {
			t.Fatal(err)
		}
		inputs = append(inputs, row)
	}

	err = stmt.Close()
	if err != nil {
		t.Fatal(err)
	}
	err = txn.Commit()
	if err != nil {
		t.Fatal(err)
	}

	rows, err := db.Query("SELECT * FROM d.t ORDER BY id")
	if err != nil {
		t.Fatal(err)
	}

	for row, in := range inputs {
		if !rows.Next() {
			t.Fatal("expected more results")
		}
		data := make([]interface{}, len(in))
		for i := range data {
			data[i] = new(interface{})
		}
		if err := rows.Scan(data...); err != nil {
			t.Fatal(err)
		}
		for i, d := range data {
			v := d.(*interface{})
			d := *v
//.........這裏部分代碼省略.........
開發者ID:BramGruneir,項目名稱:cockroach,代碼行數:101,代碼來源:copy_in_test.go

示例10: isRenderEquivalent

// isRenderEquivalent is a helper function for equivalentRenders() and
// addOrMergeRenders(). Do not use directly.
func (s *selectNode) isRenderEquivalent(exprStr string, j int) bool {
	return parser.AsStringWithFlags(s.render[j], parser.FmtSymbolicVars) == exprStr
}
開發者ID:BramGruneir,項目名稱:cockroach,代碼行數:5,代碼來源:targets.go

示例11: equivalentRenders

// equivalentRenders returns true if and only if the two render expressions
// are equivalent.
func (s *selectNode) equivalentRenders(i, j int) bool {
	firstExprStr := parser.AsStringWithFlags(s.render[i], parser.FmtSymbolicVars)
	return s.isRenderEquivalent(firstExprStr, j)
}
開發者ID:BramGruneir,項目名稱:cockroach,代碼行數:6,代碼來源:targets.go


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