Documentation
¶
Index ¶
- Constants
- Variables
- func AreDefinitelyDifferent(a DataType, b DataType) bool
- func AreTheSame(a DataType, b DataType) bool
- func IsTextDataType(a DataType) bool
- type ArrayDataType
- type BinaryDataType
- type BooleanDataType
- type DataType
- type DateDataType
- type FloatDataType
- type GeographyDataType
- type GeometryDataType
- type NumberDataType
- type ObjectDataType
- type TableDataType
- type TableDataTypeColumn
- type TextDataType
- type TimeDataType
- type TimestampLtzDataType
- type TimestampNtzDataType
- type TimestampTzDataType
- type VariantDataType
- type VectorDataType
Constants ¶
const ( DefaultBinarySize = 8 * 1024 * 1024 MaxBinarySize = 64 * 1024 * 1024 )
const ( ArrayLegacyDataType = "ARRAY" BinaryLegacyDataType = "BINARY" BooleanLegacyDataType = "BOOLEAN" DateLegacyDataType = "DATE" FloatLegacyDataType = "FLOAT" GeographyLegacyDataType = "GEOGRAPHY" GeometryLegacyDataType = "GEOMETRY" NumberLegacyDataType = "NUMBER" ObjectLegacyDataType = "OBJECT" VarcharLegacyDataType = "VARCHAR" TimeLegacyDataType = "TIME" TimestampLtzLegacyDataType = "TIMESTAMP_LTZ" TimestampNtzLegacyDataType = "TIMESTAMP_NTZ" TimestampTzLegacyDataType = "TIMESTAMP_TZ" VariantLegacyDataType = "VARIANT" // TableLegacyDataType was not a value of legacy data type in the old implementation. Left for now for an easier implementation. TableLegacyDataType = "TABLE" )
const ( DefaultNumberPrecision = 38 DefaultNumberScale = 0 )
const ( DefaultVarcharLength = 16 * 1024 * 1024 DefaultCharLength = 1 MaxVarcharLength = 128 * 1024 * 1024 )
const DefaultTimePrecision = 9
const DefaultTimestampPrecision = 9
Variables ¶
var ( NumberDataTypeSynonyms = []string{NumberLegacyDataType, "DECIMAL", "DEC", "NUMERIC"} NumberDataTypeSubTypes = []string{"INTEGER", "INT", "BIGINT", "SMALLINT", "TINYINT", "BYTEINT"} AllNumberDataTypes = append(NumberDataTypeSynonyms, NumberDataTypeSubTypes...) )
var ( TextDataTypeSynonyms = []string{VarcharLegacyDataType, "STRING", "TEXT", "NVARCHAR2", "NVARCHAR", "CHAR VARYING", "NCHAR VARYING"} TextDataTypeSubtypes = []string{"CHARACTER", "CHAR", "NCHAR"} AllTextDataTypes = append(TextDataTypeSynonyms, TextDataTypeSubtypes...) )
var ( VectorDataTypeSynonyms = []string{"VECTOR"} VectorAllowedInnerTypes = []string{"INT", "FLOAT"} )
var ArrayDataTypeSynonyms = []string{ArrayLegacyDataType}
var BinaryDataTypeSynonyms = []string{BinaryLegacyDataType, "VARBINARY"}
var BooleanDataTypeSynonyms = []string{BooleanLegacyDataType}
var DateDataTypeSynonyms = []string{DateLegacyDataType}
var FloatDataTypeSynonyms = []string{"FLOAT8", "FLOAT4", FloatLegacyDataType, "DOUBLE PRECISION", "DOUBLE", "REAL"}
var GeographyDataTypeSynonyms = []string{GeographyLegacyDataType}
var GeometryDataTypeSynonyms = []string{GeometryLegacyDataType}
var ObjectDataTypeSynonyms = []string{ObjectLegacyDataType}
var TableDataTypeSynonyms = []string{"TABLE"}
var TimeDataTypeSynonyms = []string{TimeLegacyDataType}
var TimestampLtzDataTypeSynonyms = []string{TimestampLtzLegacyDataType, "TIMESTAMPLTZ", "TIMESTAMP WITH LOCAL TIME ZONE"}
var TimestampNtzDataTypeSynonyms = []string{TimestampNtzLegacyDataType, "TIMESTAMPNTZ", "TIMESTAMP WITHOUT TIME ZONE", "DATETIME"}
var TimestampTzDataTypeSynonyms = []string{TimestampTzLegacyDataType, "TIMESTAMPTZ", "TIMESTAMP WITH TIME ZONE"}
var VariantDataTypeSynonyms = []string{VariantLegacyDataType}
Functions ¶
func AreDefinitelyDifferent ¶ added in v1.2.0
AreDefinitelyDifferent compares any two data types. The logic for the equality check has 3 values: YES, NO, and MAYBE. MAYBE is a result of Snowflake not always returning the attributes of the complex data type, e.g. NUMBER(20, 4) can be returned as NUMBER and NUMBER(38, 0) (the defaults) can also be returned as NUMBER. Because of that, they are MAYBE equal. This method is meant to be an entry point in cases where we need to be sure, that the data types are different (the NO part). Example could be the handling of the external Snowflake changes where the data type is for sure different.
The logic goes like this: - If both data types are nil it returns false. - If only one data type is nil it returns true. - It returns true for different underlying types. - For the same type it performs type-specific check.
func AreTheSame ¶
AreTheSame compares any two data types. If both data types are nil it returns true. If only one data type is nil it returns false. It returns false for different underlying types. For the same type it performs type-specific comparison.
func IsTextDataType ¶
Types ¶
type ArrayDataType ¶
type ArrayDataType struct {
// contains filtered or unexported fields
}
ArrayDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-semistructured#array It does not have synonyms. It does not have any attributes.
func (*ArrayDataType) Canonical ¶
func (t *ArrayDataType) Canonical() string
func (*ArrayDataType) ToLegacyDataTypeSql ¶
func (t *ArrayDataType) ToLegacyDataTypeSql() string
func (*ArrayDataType) ToSql ¶
func (t *ArrayDataType) ToSql() string
func (*ArrayDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *ArrayDataType) ToSqlWithoutUnknowns() string
type BinaryDataType ¶
type BinaryDataType struct {
// contains filtered or unexported fields
}
BinaryDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-text#data-types-for-binary-strings It does have synonyms that allow specifying size. Size can be known or unknown.
func (*BinaryDataType) Canonical ¶
func (t *BinaryDataType) Canonical() string
func (*BinaryDataType) ToLegacyDataTypeSql ¶
func (t *BinaryDataType) ToLegacyDataTypeSql() string
func (*BinaryDataType) ToSql ¶
func (t *BinaryDataType) ToSql() string
func (*BinaryDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *BinaryDataType) ToSqlWithoutUnknowns() string
type BooleanDataType ¶
type BooleanDataType struct {
// contains filtered or unexported fields
}
BooleanDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-logical It does not have synonyms. It does not have any attributes.
func (*BooleanDataType) Canonical ¶
func (t *BooleanDataType) Canonical() string
func (*BooleanDataType) ToLegacyDataTypeSql ¶
func (t *BooleanDataType) ToLegacyDataTypeSql() string
func (*BooleanDataType) ToSql ¶
func (t *BooleanDataType) ToSql() string
func (*BooleanDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *BooleanDataType) ToSqlWithoutUnknowns() string
type DataType ¶
type DataType interface { // ToSql formats data type explicitly specifying all arguments and using the given type (e.g. CHAR(29) for CHAR(29)). ToSql() string // ToLegacyDataTypeSql formats data type using its base type without any attributes (e.g. VARCHAR for CHAR(29)). ToLegacyDataTypeSql() string // Canonical formats the data type between ToSql and ToLegacyDataTypeSql: it uses base type but with arguments (e.g. VARCHAR(29) for CHAR(29)). Canonical() string // ToSqlWithoutUnknowns formats data type explicitly specifying all KNOWN arguments and using the given type. ToSqlWithoutUnknowns() string }
DataType is the common interface that represents all Snowflake datatypes documented in https://docs.snowflake.com/en/sql-reference/intro-summary-data-types.
func ParseDataType ¶
ParseDataType is the entry point to get the implementation of the DataType from input raw string. TODO [SNOW-1843440]: order currently matters (e.g. HasPrefix(TIME) can match also TIMESTAMP*, make the checks more precise and order-independent)
type DateDataType ¶
type DateDataType struct {
// contains filtered or unexported fields
}
DateDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-datetime#date It does not have synonyms. It does not have any attributes.
func (*DateDataType) Canonical ¶
func (t *DateDataType) Canonical() string
func (*DateDataType) ToLegacyDataTypeSql ¶
func (t *DateDataType) ToLegacyDataTypeSql() string
func (*DateDataType) ToSql ¶
func (t *DateDataType) ToSql() string
func (*DateDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *DateDataType) ToSqlWithoutUnknowns() string
type FloatDataType ¶
type FloatDataType struct {
// contains filtered or unexported fields
}
FloatDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-numeric#data-types-for-floating-point-numbers It does have synonyms. It does not have any attributes.
func (*FloatDataType) Canonical ¶
func (t *FloatDataType) Canonical() string
func (*FloatDataType) ToLegacyDataTypeSql ¶
func (t *FloatDataType) ToLegacyDataTypeSql() string
func (*FloatDataType) ToSql ¶
func (t *FloatDataType) ToSql() string
func (*FloatDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *FloatDataType) ToSqlWithoutUnknowns() string
type GeographyDataType ¶
type GeographyDataType struct {
// contains filtered or unexported fields
}
GeographyDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-geospatial#geography-data-type It does not have synonyms. It does not have any attributes.
func (*GeographyDataType) Canonical ¶
func (t *GeographyDataType) Canonical() string
func (*GeographyDataType) ToLegacyDataTypeSql ¶
func (t *GeographyDataType) ToLegacyDataTypeSql() string
func (*GeographyDataType) ToSql ¶
func (t *GeographyDataType) ToSql() string
func (*GeographyDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *GeographyDataType) ToSqlWithoutUnknowns() string
type GeometryDataType ¶
type GeometryDataType struct {
// contains filtered or unexported fields
}
GeometryDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-geospatial#geometry-data-type It does not have synonyms. It does not have any attributes.
func (*GeometryDataType) Canonical ¶
func (t *GeometryDataType) Canonical() string
func (*GeometryDataType) ToLegacyDataTypeSql ¶
func (t *GeometryDataType) ToLegacyDataTypeSql() string
func (*GeometryDataType) ToSql ¶
func (t *GeometryDataType) ToSql() string
func (*GeometryDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *GeometryDataType) ToSqlWithoutUnknowns() string
type NumberDataType ¶
type NumberDataType struct {
// contains filtered or unexported fields
}
NumberDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-numeric#data-types-for-fixed-point-numbers It does have synonyms that allow specifying precision and scale; here called synonyms. It does have synonyms that does not allow specifying precision and scale; here called subtypes. Precision and scale can be known or unknown.
func (*NumberDataType) Canonical ¶
func (t *NumberDataType) Canonical() string
func (*NumberDataType) ToLegacyDataTypeSql ¶
func (t *NumberDataType) ToLegacyDataTypeSql() string
func (*NumberDataType) ToSql ¶
func (t *NumberDataType) ToSql() string
func (*NumberDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *NumberDataType) ToSqlWithoutUnknowns() string
type ObjectDataType ¶
type ObjectDataType struct {
// contains filtered or unexported fields
}
ObjectDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-semistructured#object It does not have synonyms. It does not have any attributes.
func (*ObjectDataType) Canonical ¶
func (t *ObjectDataType) Canonical() string
func (*ObjectDataType) ToLegacyDataTypeSql ¶
func (t *ObjectDataType) ToLegacyDataTypeSql() string
func (*ObjectDataType) ToSql ¶
func (t *ObjectDataType) ToSql() string
func (*ObjectDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *ObjectDataType) ToSqlWithoutUnknowns() string
type TableDataType ¶
type TableDataType struct {
// contains filtered or unexported fields
}
TableDataType is based on https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-java#returning-tabular-data. It does not have synonyms. It consists of a list of column name + column type; may be empty. For now, we require both name and data type to be present for each column (so there are no unknowns).
func (*TableDataType) Canonical ¶
func (t *TableDataType) Canonical() string
func (*TableDataType) Columns ¶
func (t *TableDataType) Columns() []TableDataTypeColumn
func (*TableDataType) ToLegacyDataTypeSql ¶
func (t *TableDataType) ToLegacyDataTypeSql() string
func (*TableDataType) ToSql ¶
func (t *TableDataType) ToSql() string
TODO [SNOW-2054316]: this method can currently print something that won't be parsed correctly because column data types are not currently parsed (e.g. `TABLE(A NUMBER(38, 0))`)
func (*TableDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *TableDataType) ToSqlWithoutUnknowns() string
type TableDataTypeColumn ¶
type TableDataTypeColumn struct {
// contains filtered or unexported fields
}
func (*TableDataTypeColumn) ColumnName ¶
func (c *TableDataTypeColumn) ColumnName() string
func (*TableDataTypeColumn) ColumnType ¶
func (c *TableDataTypeColumn) ColumnType() DataType
type TextDataType ¶
type TextDataType struct {
// contains filtered or unexported fields
}
TextDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-text#data-types-for-text-strings It does have synonyms that allow specifying length. Length can be known or unknown. It does have synonyms that allow specifying length but differ with the default length when length is omitted; here called subtypes.
func (*TextDataType) Canonical ¶
func (t *TextDataType) Canonical() string
func (*TextDataType) ToLegacyDataTypeSql ¶
func (t *TextDataType) ToLegacyDataTypeSql() string
func (*TextDataType) ToSql ¶
func (t *TextDataType) ToSql() string
func (*TextDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *TextDataType) ToSqlWithoutUnknowns() string
type TimeDataType ¶
type TimeDataType struct {
// contains filtered or unexported fields
}
TimeDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-datetime#time It does not have synonyms. It does have optional precision attribute. Precision can be known or unknown.
func (*TimeDataType) Canonical ¶
func (t *TimeDataType) Canonical() string
func (*TimeDataType) ToLegacyDataTypeSql ¶
func (t *TimeDataType) ToLegacyDataTypeSql() string
func (*TimeDataType) ToSql ¶
func (t *TimeDataType) ToSql() string
func (*TimeDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *TimeDataType) ToSqlWithoutUnknowns() string
type TimestampLtzDataType ¶
type TimestampLtzDataType struct {
// contains filtered or unexported fields
}
TimestampLtzDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-datetime#timestamp-ltz-timestamp-ntz-timestamp-tz It does have synonyms. It does have optional precision attribute. Precision can be known or unknown.
func (*TimestampLtzDataType) Canonical ¶
func (t *TimestampLtzDataType) Canonical() string
func (*TimestampLtzDataType) ToLegacyDataTypeSql ¶
func (t *TimestampLtzDataType) ToLegacyDataTypeSql() string
func (*TimestampLtzDataType) ToSql ¶
func (t *TimestampLtzDataType) ToSql() string
func (*TimestampLtzDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *TimestampLtzDataType) ToSqlWithoutUnknowns() string
type TimestampNtzDataType ¶
type TimestampNtzDataType struct {
// contains filtered or unexported fields
}
TimestampNtzDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-datetime#timestamp-ltz-timestamp-ntz-timestamp-tz It does have synonyms. It does have optional precision attribute. Precision can be known or unknown.
func (*TimestampNtzDataType) Canonical ¶
func (t *TimestampNtzDataType) Canonical() string
func (*TimestampNtzDataType) ToLegacyDataTypeSql ¶
func (t *TimestampNtzDataType) ToLegacyDataTypeSql() string
func (*TimestampNtzDataType) ToSql ¶
func (t *TimestampNtzDataType) ToSql() string
func (*TimestampNtzDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *TimestampNtzDataType) ToSqlWithoutUnknowns() string
type TimestampTzDataType ¶
type TimestampTzDataType struct {
// contains filtered or unexported fields
}
TimestampTzDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-datetime#timestamp-ltz-timestamp-ntz-timestamp-tz It does have synonyms. It does have optional precision attribute. Precision can be known or unknown.
func (*TimestampTzDataType) Canonical ¶
func (t *TimestampTzDataType) Canonical() string
func (*TimestampTzDataType) ToLegacyDataTypeSql ¶
func (t *TimestampTzDataType) ToLegacyDataTypeSql() string
func (*TimestampTzDataType) ToSql ¶
func (t *TimestampTzDataType) ToSql() string
func (*TimestampTzDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *TimestampTzDataType) ToSqlWithoutUnknowns() string
type VariantDataType ¶
type VariantDataType struct {
// contains filtered or unexported fields
}
VariantDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-semistructured#variant It does not have synonyms. It does not have any attributes.
func (*VariantDataType) Canonical ¶
func (t *VariantDataType) Canonical() string
func (*VariantDataType) ToLegacyDataTypeSql ¶
func (t *VariantDataType) ToLegacyDataTypeSql() string
func (*VariantDataType) ToSql ¶
func (t *VariantDataType) ToSql() string
func (*VariantDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *VariantDataType) ToSqlWithoutUnknowns() string
type VectorDataType ¶
type VectorDataType struct {
// contains filtered or unexported fields
}
VectorDataType is based on https://docs.snowflake.com/en/sql-reference/data-types-vector#vector It does not have synonyms. It does have type (int or float) and dimension required attributes. Vector attributes has to be always known (can't create a vector like VECTOR or VECTOR(INT)).
func (*VectorDataType) Canonical ¶
func (t *VectorDataType) Canonical() string
func (*VectorDataType) ToLegacyDataTypeSql ¶
func (t *VectorDataType) ToLegacyDataTypeSql() string
ToLegacyDataTypeSql for vector is the only one correct because in the old implementation it was returned as DataType(dType), so a proper format.
func (*VectorDataType) ToSql ¶
func (t *VectorDataType) ToSql() string
func (*VectorDataType) ToSqlWithoutUnknowns ¶ added in v1.2.1
func (t *VectorDataType) ToSqlWithoutUnknowns() string