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


Golang parser.Type類代碼示例

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


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

示例1: pgTypeForParserType

func pgTypeForParserType(t parser.Type) pgType {
	size := -1
	if s, variable := t.Size(); !variable {
		size = int(s)
	}
	return pgType{
		oid:  t.Oid(),
		size: size,
	}
}
開發者ID:,項目名稱:,代碼行數:10,代碼來源:

示例2: SanitizeVarFreeExpr

// SanitizeVarFreeExpr verifies a default expression is valid, has the
// correct type and contains no variable expressions.
func SanitizeVarFreeExpr(expr parser.Expr, expectedType parser.Type, context string) error {
	if parser.ContainsVars(expr) {
		return exprContainsVarsError(context, expr)
	}
	typedExpr, err := parser.TypeCheck(expr, nil, expectedType)
	if err != nil {
		return err
	}
	if defaultType := typedExpr.ResolvedType(); !expectedType.Equal(defaultType) {
		return incompatibleExprTypeError(context, expectedType, defaultType)
	}
	return nil
}
開發者ID:knz,項目名稱:cockroach,代碼行數:15,代碼來源:table.go

示例3: GenerateRandomArg

// GenerateRandomArg generates a random, valid, SQL function argument of
// the spcified type.
func (r *RSG) GenerateRandomArg(typ parser.Type) string {
	if r.Intn(10) == 0 {
		return "NULL"
	}
	var v interface{}
	switch typ {
	case parser.TypeInt:
		i := r.Int63()
		i -= r.Int63()
		v = i
	case parser.TypeFloat, parser.TypeDecimal:
		v = r.Float64()
	case parser.TypeString:
		v = `'string'`
	case parser.TypeBytes:
		v = `b'bytes'`
	case parser.TypeTimestamp, parser.TypeTimestampTZ:
		t := time.Unix(0, r.Int63())
		v = fmt.Sprintf(`'%s'`, t.Format(time.RFC3339Nano))
	case parser.TypeBool:
		if r.Intn(2) == 0 {
			v = "false"
		} else {
			v = "true"
		}
	case parser.TypeDate:
		i := r.Int63()
		i -= r.Int63()
		d := parser.NewDDate(parser.DDate(i))
		v = fmt.Sprintf(`'%s'`, d)
	case parser.TypeInterval:
		d := duration.Duration{Nanos: r.Int63()}
		v = fmt.Sprintf(`'%s'`, &parser.DInterval{Duration: d})
	case parser.TypeIntArray,
		parser.TypeStringArray,
		parser.TypeAnyArray,
		parser.TypeAny:
		v = "NULL"
	default:
		switch typ.(type) {
		case parser.TTuple:
			v = "NULL"
		default:
			panic(fmt.Errorf("unknown arg type: %s (%T)", typ, typ))
		}
	}
	return fmt.Sprintf("%v::%s", v, typ.String())
}
開發者ID:BramGruneir,項目名稱:cockroach,代碼行數:50,代碼來源:rsg.go

示例4: CheckColumnType

// CheckColumnType verifies that a given value is compatible
// with the type requested by the column. If the value is a
// placeholder, the type of the placeholder gets populated.
func CheckColumnType(col ColumnDescriptor, typ parser.Type, pmap *parser.PlaceholderInfo) error {
	if typ == parser.TypeNull {
		return nil
	}

	var set parser.Type
	switch col.Type.Kind {
	case ColumnType_BOOL:
		set = parser.TypeBool
	case ColumnType_INT:
		set = parser.TypeInt
	case ColumnType_FLOAT:
		set = parser.TypeFloat
	case ColumnType_DECIMAL:
		set = parser.TypeDecimal
	case ColumnType_STRING:
		set = parser.TypeString
	case ColumnType_BYTES:
		set = parser.TypeBytes
	case ColumnType_DATE:
		set = parser.TypeDate
	case ColumnType_TIMESTAMP:
		set = parser.TypeTimestamp
	case ColumnType_TIMESTAMPTZ:
		set = parser.TypeTimestampTZ
	case ColumnType_INTERVAL:
		set = parser.TypeInterval
	default:
		return errors.Errorf("unsupported column type: %s", col.Type.Kind)
	}

	// If the value is a placeholder, then the column check above has
	// populated 'set' with a type to assign to it.
	if p, pok := typ.(parser.TPlaceholder); pok {
		if err := pmap.SetType(p.Name, set); err != nil {
			return fmt.Errorf("cannot infer type for placeholder %s from column %q: %s",
				p.Name, col.Name, err)
		}
	} else if !(typ.Equal(set) || (set == parser.TypeBytes && typ == parser.TypeString)) {
		// Not a placeholder; check that the value cast has succeeded.
		return fmt.Errorf("value type %s doesn't match type %s of column %q",
			typ, col.Type.Kind, col.Name)
	}
	return nil
}
開發者ID:jmptrader,項目名稱:cockroach,代碼行數:48,代碼來源:table.go

示例5: typByVal

func typByVal(typ parser.Type) parser.Datum {
	_, variable := typ.Size()
	return parser.MakeDBool(parser.DBool(!variable))
}
開發者ID:veteranlu,項目名稱:cockroach,代碼行數:4,代碼來源:pg_catalog.go

示例6: typLen

func typLen(typ parser.Type) *parser.DInt {
	if sz, variable := typ.Size(); !variable {
		return parser.NewDInt(parser.DInt(sz))
	}
	return negOneVal
}
開發者ID:veteranlu,項目名稱:cockroach,代碼行數:6,代碼來源:pg_catalog.go


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