本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/sql/parser.Name函数的典型用法代码示例。如果您正苦于以下问题:Golang Name函数的具体用法?Golang Name怎么用?Golang Name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Name函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getTableNames
// getTableNames implements the SchemaAccessor interface.
func (p *planner) getTableNames(dbDesc *sqlbase.DatabaseDescriptor) (parser.TableNames, error) {
if e, ok := p.session.virtualSchemas.getVirtualSchemaEntry(dbDesc.Name); ok {
return e.tableNames(), nil
}
prefix := sqlbase.MakeNameMetadataKey(dbDesc.ID, "")
sr, err := p.txn.Scan(prefix, prefix.PrefixEnd(), 0)
if err != nil {
return nil, err
}
var tableNames parser.TableNames
for _, row := range sr {
_, tableName, err := encoding.DecodeUnsafeStringAscending(
bytes.TrimPrefix(row.Key, prefix), nil)
if err != nil {
return nil, err
}
tn := parser.TableName{
DatabaseName: parser.Name(dbDesc.Name),
TableName: parser.Name(tableName),
}
tableNames = append(tableNames, tn)
}
return tableNames, nil
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:27,代码来源:table.go
示例2: userTablesAndDBsMatchingName
func userTablesAndDBsMatchingName(
descs []sqlbase.Descriptor, name parser.TableName,
) ([]sqlbase.Descriptor, error) {
tableName := name.TableName.Normalize()
dbName := name.DatabaseName.Normalize()
matches := make([]sqlbase.Descriptor, 0, len(descs))
dbIDsToName := make(map[sqlbase.ID]string)
for _, desc := range descs {
if db := desc.GetDatabase(); db != nil {
if db.ID == keys.SystemDatabaseID {
continue // Not a user database.
}
if n := parser.Name(db.Name).Normalize(); dbName == "*" || n == dbName {
matches = append(matches, desc)
dbIDsToName[db.ID] = n
}
continue
}
}
for _, desc := range descs {
if table := desc.GetTable(); table != nil {
if _, ok := dbIDsToName[table.ParentID]; !ok {
continue
}
if tableName == "*" || parser.Name(table.Name).Normalize() == tableName {
matches = append(matches, desc)
}
}
}
return matches, nil
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:32,代码来源:backup.go
示例3: runRestore
func runRestore(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("input basepath argument is required")
}
base := args[0]
ctx := context.Background()
kvDB, stopper, err := makeDBClient()
if err != nil {
return err
}
defer stopper.Stop()
tableName := parser.TableName{
DatabaseName: parser.Name(backupCtx.database),
TableName: parser.Name(backupCtx.table),
}
restored, err := sql.Restore(ctx, *kvDB, base, tableName)
if err != nil {
return err
}
for _, table := range restored {
fmt.Printf("Restored table %q\n", table.Name)
}
fmt.Printf("Restored from %s\n", base)
return nil
}
开发者ID:hvaara,项目名称:cockroach,代码行数:28,代码来源:backup.go
示例4: upsertExprsAndIndex
// upsertExprsAndIndex returns the upsert conflict index and the (possibly
// synthetic) SET expressions used when a row conflicts.
func upsertExprsAndIndex(
tableDesc *sqlbase.TableDescriptor,
onConflict parser.OnConflict,
insertCols []sqlbase.ColumnDescriptor,
) (parser.UpdateExprs, *sqlbase.IndexDescriptor, error) {
if onConflict.IsUpsertAlias() {
// The UPSERT syntactic sugar is the same as the longhand specifying the
// primary index as the conflict index and SET expressions for the columns
// in insertCols minus any columns in the conflict index. Example:
// `UPSERT INTO abc VALUES (1, 2, 3)` is syntactic sugar for
// `INSERT INTO abc VALUES (1, 2, 3) ON CONFLICT a DO UPDATE SET b = 2, c = 3`.
conflictIndex := &tableDesc.PrimaryIndex
indexColSet := make(map[sqlbase.ColumnID]struct{}, len(conflictIndex.ColumnIDs))
for _, colID := range conflictIndex.ColumnIDs {
indexColSet[colID] = struct{}{}
}
updateExprs := make(parser.UpdateExprs, 0, len(insertCols))
for _, c := range insertCols {
if _, ok := indexColSet[c.ID]; !ok {
names := parser.UnresolvedNames{
parser.UnresolvedName{parser.Name(c.Name)},
}
expr := &parser.ColumnItem{
TableName: upsertExcludedTable,
ColumnName: parser.Name(c.Name),
}
updateExprs = append(updateExprs, &parser.UpdateExpr{Names: names, Expr: expr})
}
}
return updateExprs, conflictIndex, nil
}
indexMatch := func(index sqlbase.IndexDescriptor) bool {
if !index.Unique {
return false
}
if len(index.ColumnNames) != len(onConflict.Columns) {
return false
}
for i, colName := range index.ColumnNames {
if parser.ReNormalizeName(colName) != onConflict.Columns[i].Normalize() {
return false
}
}
return true
}
if indexMatch(tableDesc.PrimaryIndex) {
return onConflict.Exprs, &tableDesc.PrimaryIndex, nil
}
for _, index := range tableDesc.Indexes {
if indexMatch(index) {
return onConflict.Exprs, &index, nil
}
}
return nil, nil, fmt.Errorf("there is no unique or exclusion constraint matching the ON CONFLICT specification")
}
开发者ID:knz,项目名称:cockroach,代码行数:59,代码来源:upsert.go
示例5: tableNames
func (e virtualSchemaEntry) tableNames() parser.TableNames {
var res parser.TableNames
for _, tableName := range e.orderedTableNames {
tn := parser.TableName{
DatabaseName: parser.Name(e.desc.Name),
TableName: parser.Name(tableName),
}
res = append(res, tn)
}
return res
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:11,代码来源:virtual_schema.go
示例6: getQualifiedTableName
// getQualifiedTableName returns the database-qualified name of the table
// or view represented by the provided descriptor.
func (p *planner) getQualifiedTableName(desc *sqlbase.TableDescriptor) (string, error) {
dbDesc, err := sqlbase.GetDatabaseDescFromID(p.txn, desc.ParentID)
if err != nil {
return "", err
}
tbName := parser.TableName{
DatabaseName: parser.Name(dbDesc.Name),
TableName: parser.Name(desc.Name),
}
return tbName.String(), nil
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:13,代码来源:table.go
示例7: queryNamespace
func queryNamespace(conn *sqlConn, parentID sqlbase.ID, name string) (sqlbase.ID, error) {
rows, err := makeQuery(
`SELECT id FROM system.namespace WHERE parentID = $1 AND name = $2`,
parentID, parser.Name(name).Normalize())(conn)
if err != nil {
return 0, err
}
defer func() { _ = rows.Close() }()
if err != nil {
return 0, fmt.Errorf("%s not found: %v", name, err)
}
if len(rows.Columns()) != 1 {
return 0, fmt.Errorf("unexpected result columns: %d", len(rows.Columns()))
}
vals := make([]driver.Value, 1)
if err := rows.Next(vals); err != nil {
return 0, err
}
switch t := vals[0].(type) {
case int64:
return sqlbase.ID(t), nil
default:
return 0, fmt.Errorf("unexpected result type: %T", vals[0])
}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:26,代码来源:zone.go
示例8: GetUserHashedPassword
// GetUserHashedPassword returns the hashedPassword for the given username if
// found in system.users.
func GetUserHashedPassword(
ctx context.Context, executor *Executor, metrics *MemoryMetrics, username string,
) ([]byte, error) {
normalizedUsername := parser.Name(username).Normalize()
// The root user is not in system.users.
if normalizedUsername == security.RootUser {
return nil, nil
}
var hashedPassword []byte
if err := executor.cfg.DB.Txn(ctx, func(txn *client.Txn) error {
p := makeInternalPlanner("get-pwd", txn, security.RootUser, metrics)
defer finishInternalPlanner(p)
const getHashedPassword = `SELECT hashedPassword FROM system.users ` +
`WHERE username=$1`
values, err := p.queryRow(getHashedPassword, normalizedUsername)
if err != nil {
return errors.Errorf("error looking up user %s", normalizedUsername)
}
if len(values) == 0 {
return errors.Errorf("user %s does not exist", normalizedUsername)
}
hashedPassword = []byte(*(values[0].(*parser.DBytes)))
return nil
}); err != nil {
return nil, err
}
return hashedPassword, nil
}
开发者ID:knz,项目名称:cockroach,代码行数:32,代码来源:user.go
示例9: quoteNames
// quoteName quotes based on Traditional syntax and adds commas between names.
func quoteNames(names ...string) string {
nameList := make(parser.NameList, len(names))
for i, n := range names {
nameList[i] = parser.Name(n)
}
return parser.AsString(nameList)
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:8,代码来源:show.go
示例10: extractFunc
// extractFunc returns an aggregateFuncHolder for a given SelectExpr specifying
// an aggregation function.
func (ag *aggregator) extractFunc(
expr AggregatorSpec_Expr, eh *exprHelper,
) (*aggregateFuncHolder, error) {
if expr.Func == AggregatorSpec_IDENT {
fn := ag.newAggregateFuncHolder(parser.NewIdentAggregate)
return fn, nil
}
// In order to reuse the aggregate functions as defined in the parser
// package we are relying on the fact the each name defined in the Func enum
// within the AggregatorSpec matches a SQL function name known to the parser.
// See pkg/sql/parser/aggregate_builtins.go for the aggregate builtins we
// are repurposing.
p := &parser.FuncExpr{
Func: parser.ResolvableFunctionReference{
FunctionReference: parser.UnresolvedName{parser.Name(expr.Func.String())},
},
Exprs: []parser.Expr{eh.vars.IndexedVar(int(expr.ColIdx))},
}
_, err := p.TypeCheck(nil, parser.NoTypePreference)
if err != nil {
return nil, err
}
if agg := p.GetAggregateConstructor(); agg != nil {
fn := ag.newAggregateFuncHolder(agg)
if expr.Distinct {
fn.seen = make(map[string]struct{})
}
return fn, nil
}
return nil, errors.Errorf("unable to get aggregate constructor for %s",
AggregatorSpec_Func_name[int32(expr.Func)])
}
开发者ID:veteranlu,项目名称:cockroach,代码行数:36,代码来源:aggregator.go
示例11: newReturningHelper
// newReturningHelper creates a new returningHelper for use by an
// insert/update node.
func (p *planner) newReturningHelper(
r parser.ReturningExprs,
desiredTypes []parser.Type,
alias string,
tablecols []sqlbase.ColumnDescriptor,
) (*returningHelper, error) {
rh := &returningHelper{
p: p,
}
if len(r) == 0 {
return rh, nil
}
for _, e := range r {
if err := p.parser.AssertNoAggregationOrWindowing(
e.Expr, "RETURNING", p.session.SearchPath,
); err != nil {
return nil, err
}
}
rh.columns = make(ResultColumns, 0, len(r))
aliasTableName := parser.TableName{TableName: parser.Name(alias)}
rh.source = newSourceInfoForSingleTable(aliasTableName, makeResultColumns(tablecols))
rh.exprs = make([]parser.TypedExpr, 0, len(r))
ivarHelper := parser.MakeIndexedVarHelper(rh, len(tablecols))
for i, target := range r {
// Pre-normalize VarNames at the top level so that checkRenderStar can see stars.
if err := target.NormalizeTopLevelVarName(); err != nil {
return nil, err
}
if isStar, cols, typedExprs, err := checkRenderStar(target, rh.source, ivarHelper); err != nil {
return nil, err
} else if isStar {
rh.exprs = append(rh.exprs, typedExprs...)
rh.columns = append(rh.columns, cols...)
continue
}
// When generating an output column name it should exactly match the original
// expression, so determine the output column name before we perform any
// manipulations to the expression.
outputName := getRenderColName(target)
desired := parser.TypeAny
if len(desiredTypes) > i {
desired = desiredTypes[i]
}
typedExpr, err := rh.p.analyzeExpr(target.Expr, multiSourceInfo{rh.source}, ivarHelper, desired, false, "")
if err != nil {
return nil, err
}
rh.exprs = append(rh.exprs, typedExpr)
rh.columns = append(rh.columns, ResultColumn{Name: outputName, Typ: typedExpr.ResolvedType()})
}
return rh, nil
}
开发者ID:nvanbenschoten,项目名称:cockroach,代码行数:61,代码来源:returning.go
示例12: Format
// Format pretty-prints the orderingInfo to a stream.
// If columns is not nil, column names are printed instead of column indexes.
func (ord orderingInfo) Format(buf *bytes.Buffer, columns ResultColumns) {
sep := ""
// Print the exact match columns. We sort them to ensure
// a deterministic output order.
cols := make([]int, 0, len(ord.exactMatchCols))
for i := range ord.exactMatchCols {
cols = append(cols, i)
}
sort.Ints(cols)
for _, i := range cols {
buf.WriteString(sep)
sep = ","
buf.WriteByte('=')
if columns == nil || i >= len(columns) {
fmt.Fprintf(buf, "%d", i)
} else {
parser.Name(columns[i].Name).Format(buf, parser.FmtSimple)
}
}
// Print the ordering columns and for each their sort order.
for _, o := range ord.ordering {
buf.WriteString(sep)
sep = ","
prefix := byte('+')
if o.Direction == encoding.Descending {
prefix = '-'
}
buf.WriteByte(prefix)
if columns == nil || o.ColIdx >= len(columns) {
fmt.Fprintf(buf, "%d", o.ColIdx)
} else {
parser.Name(columns[o.ColIdx].Name).Format(buf, parser.FmtSimple)
}
}
if ord.unique {
buf.WriteString(sep)
buf.WriteString("unique")
}
}
开发者ID:knz,项目名称:cockroach,代码行数:47,代码来源:ordering.go
示例13: indexDefFromDescriptor
// indexDefFromDescriptor creates an index definition (`CREATE INDEX ... ON (...)`) from
// and index descriptor by reconstructing a CreateIndex parser node and calling its
// String method.
func indexDefFromDescriptor(
p *planner,
db *sqlbase.DatabaseDescriptor,
table *sqlbase.TableDescriptor,
index *sqlbase.IndexDescriptor,
) (string, error) {
indexDef := parser.CreateIndex{
Name: parser.Name(index.Name),
Table: parser.NormalizableTableName{
TableNameReference: &parser.TableName{
DatabaseName: parser.Name(db.Name),
TableName: parser.Name(table.Name),
},
},
Unique: index.Unique,
Columns: make(parser.IndexElemList, len(index.ColumnNames)),
Storing: make(parser.NameList, len(index.StoreColumnNames)),
}
for i, name := range index.ColumnNames {
elem := parser.IndexElem{
Column: parser.Name(name),
Direction: parser.Ascending,
}
if index.ColumnDirections[i] == sqlbase.IndexDescriptor_DESC {
elem.Direction = parser.Descending
}
indexDef.Columns[i] = elem
}
for i, name := range index.StoreColumnNames {
indexDef.Storing[i] = parser.Name(name)
}
if len(index.Interleave.Ancestors) > 0 {
intl := index.Interleave
parentTable, err := sqlbase.GetTableDescFromID(p.txn, intl.Ancestors[len(intl.Ancestors)-1].TableID)
if err != nil {
return "", err
}
var sharedPrefixLen int
for _, ancestor := range intl.Ancestors {
sharedPrefixLen += int(ancestor.SharedPrefixLen)
}
fields := index.ColumnNames[:sharedPrefixLen]
intlDef := &parser.InterleaveDef{
Parent: parser.NormalizableTableName{
TableNameReference: &parser.TableName{
TableName: parser.Name(parentTable.Name),
},
},
Fields: make(parser.NameList, len(fields)),
}
for i, field := range fields {
intlDef.Fields[i] = parser.Name(field)
}
indexDef.Interleave = intlDef
}
return indexDef.String(), nil
}
开发者ID:veteranlu,项目名称:cockroach,代码行数:60,代码来源:pg_catalog.go
示例14: GetTableSpan
// GetTableSpan gets the key span for a SQL table, including any indices.
func (ie InternalExecutor) GetTableSpan(
user string, txn *client.Txn, dbName, tableName string,
) (roachpb.Span, error) {
// Lookup the table ID.
p := makeInternalPlanner("get-table-span", txn, user, ie.LeaseManager.memMetrics)
defer finishInternalPlanner(p)
p.leaseMgr = ie.LeaseManager
tn := parser.TableName{DatabaseName: parser.Name(dbName), TableName: parser.Name(tableName)}
tableID, err := getTableID(p, &tn)
if err != nil {
return roachpb.Span{}, err
}
// Determine table data span.
tablePrefix := keys.MakeTablePrefix(uint32(tableID))
tableStartKey := roachpb.Key(tablePrefix)
tableEndKey := tableStartKey.PrefixEnd()
return roachpb.Span{Key: tableStartKey, EndKey: tableEndKey}, nil
}
开发者ID:knz,项目名称:cockroach,代码行数:21,代码来源:internal.go
示例15: getGeneratorPlan
func (p *planner) getGeneratorPlan(t *parser.FuncExpr) (planDataSource, error) {
plan, name, err := p.makeGenerator(t)
if err != nil {
return planDataSource{}, err
}
tn := parser.TableName{TableName: parser.Name(name)}
return planDataSource{
info: newSourceInfoForSingleTable(tn, plan.Columns()),
plan: plan,
}, nil
}
开发者ID:nvanbenschoten,项目名称:cockroach,代码行数:11,代码来源:data_source.go
示例16: handleAuthentication
// handleAuthentication should discuss with the client to arrange
// authentication and update c.sessionArgs with the authenticated user's
// name, if different from the one given initially. Note: at this
// point the sql.Session does not exist yet! If need exists to access the
// database to look up authentication data, use the internal executor.
func (c *v3Conn) handleAuthentication(ctx context.Context, insecure bool) error {
if tlsConn, ok := c.conn.(*tls.Conn); ok {
var authenticationHook security.UserAuthHook
// Check that the requested user exists and retrieve the hashed
// password in case password authentication is needed.
hashedPassword, err := sql.GetUserHashedPassword(
ctx, c.executor, c.metrics.internalMemMetrics, c.sessionArgs.User,
)
if err != nil {
return c.sendInternalError(err.Error())
}
tlsState := tlsConn.ConnectionState()
// If no certificates are provided, default to password
// authentication.
if len(tlsState.PeerCertificates) == 0 {
password, err := c.sendAuthPasswordRequest()
if err != nil {
return c.sendInternalError(err.Error())
}
authenticationHook = security.UserAuthPasswordHook(
insecure, password, hashedPassword,
)
} else {
// Normalize the username contained in the certificate.
tlsState.PeerCertificates[0].Subject.CommonName = parser.Name(
tlsState.PeerCertificates[0].Subject.CommonName,
).Normalize()
var err error
authenticationHook, err = security.UserAuthCertHook(insecure, &tlsState)
if err != nil {
return c.sendInternalError(err.Error())
}
}
if err := authenticationHook(c.sessionArgs.User, true /* public */); err != nil {
return c.sendInternalError(err.Error())
}
}
c.writeBuf.initMsg(serverMsgAuth)
c.writeBuf.putInt32(authOK)
return c.writeBuf.finishMsg(c.wr)
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:50,代码来源:v3.go
示例17: commonColumns
// commonColumns returns the names of columns common on the
// right and left sides, for use by NATURAL JOIN.
func commonColumns(left, right *dataSourceInfo) parser.NameList {
var res parser.NameList
for _, cLeft := range left.sourceColumns {
if cLeft.hidden {
continue
}
for _, cRight := range right.sourceColumns {
if cRight.hidden {
continue
}
if parser.ReNormalizeName(cLeft.Name) == parser.ReNormalizeName(cRight.Name) {
res = append(res, parser.Name(cLeft.Name))
}
}
}
return res
}
开发者ID:maxlang,项目名称:cockroach,代码行数:20,代码来源:join.go
示例18: ExplainPlan
func (s *selectNode) ExplainPlan(v bool) (name, description string, children []planNode) {
subplans := []planNode{s.source.plan}
subplans = s.planner.collectSubqueryPlans(s.filter, subplans)
for _, e := range s.render {
subplans = s.planner.collectSubqueryPlans(e, subplans)
}
if len(subplans) == 1 && !v {
return s.source.plan.ExplainPlan(v)
}
var buf bytes.Buffer
buf.WriteString("from (")
for i, col := range s.source.info.sourceColumns {
if i > 0 {
buf.WriteString(", ")
}
if col.hidden {
buf.WriteByte('*')
}
alias, found := s.source.info.findTableAlias(i)
if found {
parser.FormatNode(&buf, parser.FmtSimple, &alias)
} else {
buf.WriteByte('_')
}
buf.WriteByte('.')
parser.FormatNode(&buf, parser.FmtSimple, parser.Name(col.Name))
}
buf.WriteByte(')')
name = "render/filter"
if s.explain != explainNone {
name = fmt.Sprintf("%s(%s)", name, explainStrings[s.explain])
}
return name, buf.String(), subplans
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:41,代码来源:select.go
示例19: databaseFromSearchPath
// databaseFromSearchPath returns the first database in the session's SearchPath
// that contains the specified table. If the table can't be found, we return the
// session database.
func (p *planner) databaseFromSearchPath(tn *parser.TableName) (string, error) {
t := *tn
for _, database := range p.session.SearchPath {
t.DatabaseName = parser.Name(database)
desc, err := p.getTableOrViewDesc(&t)
if err != nil {
if _, ok := err.(*sqlbase.ErrUndefinedDatabase); ok {
// Keep iterating through search path if a database in the search path
// doesn't exist.
continue
}
return "", err
}
if desc != nil {
// The table or view exists in this database, so return it.
return t.Database(), nil
}
}
// If we couldn't find the table or view in the search path, default to the
// database set by the user.
return p.session.Database, nil
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:25,代码来源:table.go
示例20: formatColumns
// formatColumns converts a column signature for a data source /
// planNode to a string. The column types are printed iff the 2nd
// argument specifies so.
func formatColumns(cols ResultColumns, printTypes bool) string {
var buf bytes.Buffer
buf.WriteByte('(')
for i, rCol := range cols {
if i > 0 {
buf.WriteString(", ")
}
parser.Name(rCol.Name).Format(&buf, parser.FmtSimple)
// Output extra properties like [hidden,omitted].
hasProps := false
outputProp := func(prop string) {
if hasProps {
buf.WriteByte(',')
} else {
buf.WriteByte('[')
}
hasProps = true
buf.WriteString(prop)
}
if rCol.hidden {
outputProp("hidden")
}
if rCol.omitted {
outputProp("omitted")
}
if hasProps {
buf.WriteByte(']')
}
if printTypes {
buf.WriteByte(' ')
buf.WriteString(rCol.Typ.String())
}
}
buf.WriteByte(')')
return buf.String()
}
开发者ID:EvilMcJerkface,项目名称:cockroach,代码行数:40,代码来源:explain_plan.go
注:本文中的github.com/cockroachdb/cockroach/pkg/sql/parser.Name函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论