types

package
v0.0.0-...-c6cbf5f Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultTypes = map[string]DataType{
		timestamp.Key:               TIMESTAMP,
		"eventn_ctx_utc_time":       TIMESTAMP,
		"eventn_ctx_interval_start": TIMESTAMP,
		"eventn_ctx_interval_end":   TIMESTAMP,
		"utc_time":                  TIMESTAMP,
		"interval_start":            TIMESTAMP,
		"interval_end":              TIMESTAMP,
	}
)

Typecast tree

 STRING(4)
/      \

FLOAT64(3) TIMESTAMP(5)

  |
INT64(2)
  |
BOOL(1)

Functions

func Convert

func Convert(toType DataType, v any) (any, error)

Convert returns converted into toType value or error if occurred

func IsConvertible

func IsConvertible(from DataType, to DataType) bool

IsConvertible returns false if there isn't any rule for converting from DataType into to DataType

func ObjectValuesToString

func ObjectValuesToString(header []string, valueArgs []any) string

func ParseTimestamp

func ParseTimestamp(rawTimestamp any) (time.Time, error)

func ReformatNumberValue

func ReformatNumberValue(v any) any

ReformatNumberValue process json.Number types into int64 or float64 note: jsoniter.Unmarshal returns json.Number type that can be int or float

we have to check does json number have dot in string representation

if have -> return float64 otherwise int64

func ReformatTimeValue

func ReformatTimeValue(value any) any

ReformatTimeValue processes string with ISO DateTime or Golang layout into time.Time

func ReformatValue

func ReformatValue(v any) any

ReformatNumberValue process json.Number types into int64 or float64 processes string with ISO DateTime or Golang layout into time.Time note: jsoniter.Unmarshal returns json.Number type that can be int or float

we have to check does json number have dot in string representation

if have -> return float64 otherwise int64

func StringFromType

func StringFromType(dataType DataType) (string, error)

StringFromType returns string representation of DataType or error if mapping doesn't exist

func StringToFloat

func StringToFloat(v any) (any, error)

StringToFloat return float64 value from string or error if unconvertable

func StringToInt

func StringToInt(v any) (any, error)

StringToInt returns int representation of input string or error if unconvertable

func StringWithCommasToFloat

func StringWithCommasToFloat(v any) (any, error)

StringWithCommasToFloat return float64 value from string (1,200.50)

Types

type AbstractMarshaller

type AbstractMarshaller struct {
	// contains filtered or unexported fields
}

func (*AbstractMarshaller) Equal

func (am *AbstractMarshaller) Equal(m Marshaller) bool

type CSVMarshaller

type CSVMarshaller struct {
	AbstractMarshaller
	// contains filtered or unexported fields
}

func (*CSVMarshaller) Compression

func (cm *CSVMarshaller) Compression() FileCompression

func (*CSVMarshaller) Flush

func (cm *CSVMarshaller) Flush() error

func (*CSVMarshaller) Format

func (cm *CSVMarshaller) Format() FileFormat

func (*CSVMarshaller) Init

func (cm *CSVMarshaller) Init(writer io.Writer, header []string) error

func (*CSVMarshaller) Marshal

func (cm *CSVMarshaller) Marshal(object ...Object) error

Marshal marshals input object as csv values string with delimiter

func (*CSVMarshaller) NeedHeader

func (cm *CSVMarshaller) NeedHeader() bool

type ConvertFunc

type ConvertFunc func(v any) (any, error)

ConvertFunc is a function for a certain DataType conversion

type DataType

type DataType int

DataType is a type representation of common data types

const (

	//UNKNOWN type for error cases
	UNKNOWN DataType = iota
	//BOOL type for boolean values
	BOOL
	//INT64 type for int values
	INT64
	//FLOAT64 type for float values
	FLOAT64
	//STRING type for string values
	STRING
	//TIMESTAMP type for string values that match timestamp pattern
	TIMESTAMP
	//JSON type for json values
	JSON
)

func DataTypePtr

func DataTypePtr(dt DataType) *DataType

func GetCommonAncestorType

func GetCommonAncestorType(t1, t2 DataType) DataType

GetCommonAncestorType returns lowest common ancestor type

func TypeFromString

func TypeFromString(t string) (DataType, error)

TypeFromString returns DataType from input string or error if mapping doesn't exist

func TypeFromValue

func TypeFromValue(v any) (DataType, error)

TypeFromValue return DataType from v type

func (DataType) String

func (dt DataType) String() string

type ErrorPayload

type ErrorPayload struct {
	Dataset         string
	Bucket          string
	Project         string
	Database        string
	Cluster         string
	Schema          string
	Table           string
	Partition       string
	PrimaryKeys     []string
	Statement       string
	Values          []any
	ValuesMapString string
	TotalObjects    int
}

func (*ErrorPayload) String

func (ep *ErrorPayload) String() string

type FileCompression

type FileCompression string
const (
	FileCompressionGZIP    FileCompression = "gzip"
	FileCompressionNONE    FileCompression = "none"
	FileCompressionUNKNOWN FileCompression = ""
)

type FileFormat

type FileFormat string
const (
	FileFormatCSV        FileFormat = "csv"
	FileFormatNDJSON     FileFormat = "ndjson"
	FileFormatNDJSONFLAT FileFormat = "ndjson_flat"
)

type JSONMarshaller

type JSONMarshaller struct {
	AbstractMarshaller
	// contains filtered or unexported fields
}

func (*JSONMarshaller) Compression

func (jm *JSONMarshaller) Compression() FileCompression

func (*JSONMarshaller) Flush

func (jm *JSONMarshaller) Flush() error

func (*JSONMarshaller) Format

func (jm *JSONMarshaller) Format() FileFormat

func (*JSONMarshaller) Init

func (jm *JSONMarshaller) Init(writer io.Writer, _ []string) error

func (*JSONMarshaller) Marshal

func (jm *JSONMarshaller) Marshal(object ...Object) error

Marshal object as json

func (*JSONMarshaller) NeedHeader

func (jm *JSONMarshaller) NeedHeader() bool

type Marshaller

type Marshaller interface {
	Init(writer io.Writer, header []string) error
	Marshal(...Object) error
	Flush() error
	NeedHeader() bool
	Format() FileFormat
	Compression() FileCompression
	Equal(Marshaller) bool
}

func NewMarshaller

func NewMarshaller(format FileFormat, compression FileCompression) (Marshaller, error)

type Object

type Object map[string]any

TODO: move type conversion here

func (Object) Id

func (o Object) Id() any

type SQLColumn

type SQLColumn struct {
	Type     string `json:"type,omitempty"`
	DdlType  string `json:"ddlType,omitempty"`
	Override bool   `json:"override,omitempty"`
	DataType DataType
	// New column represents not commited part of a table schema
	New bool
}

func (SQLColumn) GetDDLType

func (c SQLColumn) GetDDLType() string

type SQLTypes

type SQLTypes map[string]SQLColumn

func (SQLTypes) With

func (s SQLTypes) With(name, sqlType string) SQLTypes

func (SQLTypes) WithDDL

func (s SQLTypes) WithDDL(name, sqlType, ddlType string) SQLTypes

Jump to

Keyboard shortcuts

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