datatypes

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	DefaultNumberPrecision = 38
	DefaultNumberScale     = 0
)
View Source
const (
	DefaultVarcharLength = 16777216
	DefaultCharLength    = 1
)
View Source
const DefaultBinarySize = 8388608
View Source
const DefaultTimePrecision = 9
View Source
const DefaultTimestampPrecision = 9

Variables

View Source
var (
	NumberDataTypeSynonyms = []string{NumberLegacyDataType, "DECIMAL", "DEC", "NUMERIC"}
	NumberDataTypeSubTypes = []string{"INTEGER", "INT", "BIGINT", "SMALLINT", "TINYINT", "BYTEINT"}
	AllNumberDataTypes     = append(NumberDataTypeSynonyms, NumberDataTypeSubTypes...)
)
View Source
var (
	TextDataTypeSynonyms = []string{VarcharLegacyDataType, "STRING", "TEXT", "NVARCHAR2", "NVARCHAR", "CHAR VARYING", "NCHAR VARYING"}
	TextDataTypeSubtypes = []string{"CHARACTER", "CHAR", "NCHAR"}
	AllTextDataTypes     = append(TextDataTypeSynonyms, TextDataTypeSubtypes...)
)
View Source
var (
	VectorDataTypeSynonyms  = []string{"VECTOR"}
	VectorAllowedInnerTypes = []string{"INT", "FLOAT"}
)
View Source
var ArrayDataTypeSynonyms = []string{ArrayLegacyDataType}
View Source
var BinaryDataTypeSynonyms = []string{BinaryLegacyDataType, "VARBINARY"}
View Source
var BooleanDataTypeSynonyms = []string{BooleanLegacyDataType}
View Source
var DateDataTypeSynonyms = []string{DateLegacyDataType}
View Source
var FloatDataTypeSynonyms = []string{"FLOAT8", "FLOAT4", FloatLegacyDataType, "DOUBLE PRECISION", "DOUBLE", "REAL"}
View Source
var GeographyDataTypeSynonyms = []string{GeographyLegacyDataType}
View Source
var GeometryDataTypeSynonyms = []string{GeometryLegacyDataType}
View Source
var ObjectDataTypeSynonyms = []string{ObjectLegacyDataType}
View Source
var TableDataTypeSynonyms = []string{"TABLE"}
View Source
var TimeDataTypeSynonyms = []string{TimeLegacyDataType}
View Source
var TimestampLtzDataTypeSynonyms = []string{TimestampLtzLegacyDataType, "TIMESTAMPLTZ", "TIMESTAMP WITH LOCAL TIME ZONE"}
View Source
var TimestampNtzDataTypeSynonyms = []string{TimestampNtzLegacyDataType, "TIMESTAMPNTZ", "TIMESTAMP WITHOUT TIME ZONE", "DATETIME"}
View Source
var TimestampTzDataTypeSynonyms = []string{TimestampTzLegacyDataType, "TIMESTAMPTZ", "TIMESTAMP WITH TIME ZONE"}
View Source
var VariantDataTypeSynonyms = []string{VariantLegacyDataType}

Functions

func AreTheSame

func AreTheSame(a DataType, b DataType) bool

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

func IsTextDataType(a DataType) bool

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

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.

func (*BinaryDataType) Canonical

func (t *BinaryDataType) Canonical() string

func (*BinaryDataType) ToLegacyDataTypeSql

func (t *BinaryDataType) ToLegacyDataTypeSql() string

func (*BinaryDataType) ToSql

func (t *BinaryDataType) ToSql() 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

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
}

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

func ParseDataType(raw string) (DataType, error)

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

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

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

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

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.

func (*NumberDataType) Canonical

func (t *NumberDataType) Canonical() string

func (*NumberDataType) ToLegacyDataTypeSql

func (t *NumberDataType) ToLegacyDataTypeSql() string

func (*NumberDataType) ToSql

func (t *NumberDataType) ToSql() 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

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.

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

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. 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

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.

func (*TimeDataType) Canonical

func (t *TimeDataType) Canonical() string

func (*TimeDataType) ToLegacyDataTypeSql

func (t *TimeDataType) ToLegacyDataTypeSql() string

func (*TimeDataType) ToSql

func (t *TimeDataType) ToSql() 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.

func (*TimestampLtzDataType) Canonical

func (t *TimestampLtzDataType) Canonical() string

func (*TimestampLtzDataType) ToLegacyDataTypeSql

func (t *TimestampLtzDataType) ToLegacyDataTypeSql() string

func (*TimestampLtzDataType) ToSql

func (t *TimestampLtzDataType) ToSql() 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.

func (*TimestampNtzDataType) Canonical

func (t *TimestampNtzDataType) Canonical() string

func (*TimestampNtzDataType) ToLegacyDataTypeSql

func (t *TimestampNtzDataType) ToLegacyDataTypeSql() string

func (*TimestampNtzDataType) ToSql

func (t *TimestampNtzDataType) ToSql() 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.

func (*TimestampTzDataType) Canonical

func (t *TimestampTzDataType) Canonical() string

func (*TimestampTzDataType) ToLegacyDataTypeSql

func (t *TimestampTzDataType) ToLegacyDataTypeSql() string

func (*TimestampTzDataType) ToSql

func (t *TimestampTzDataType) ToSql() 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

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.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL