Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrUnsupportedRedshiftType - ErrUnsupportedRedshiftType = errors.New("ErrUnsupportedRedshiftType") // ErrUnuspportedDistributionStyle - ErrUnuspportedDistributionStyle = errors.New("ErrUnuspportedDistributionStyle") )
Functions ¶
func CreateTableStatement ¶
func CreateTableStatement(cfg CreateConfig) (string, error)
CreateTableStatement -
Example ¶
ExampleCreateTableStatement -
package main import ( "encoding/json" "fmt" "github.com/khezen/avro" "github.com/khezen/avro/redshiftavro" ) func main() { schemaBytes := []byte(` { "type": "record", "namespace": "blog", "name": "posts", "fields": [ { "name": "ID", "type": "int" }, { "name": "title", "type": "string" }, { "name": "body", "type": "bytes" }, { "name": "content_type", "type": [ "string", "null" ], "default": "text/markdown; charset=UTF-8" }, { "name": "post_date", "type": { "type": "int", "doc":"datetime", "logicalType": "timestamp" } }, { "name": "update_date", "type": [ "null", { "type": "int", "doc":"datetime", "logicalType": "timestamp" } ] }, { "name": "reading_time_minutes", "type": [ "null", { "type": "bytes", "logicalType": "decimal", "precision": 3, "scale": 1 } ] } ] }`) var anySchema avro.AnySchema err := json.Unmarshal(schemaBytes, &anySchema) if err != nil { panic(err) } schema := anySchema.Schema().(*avro.RecordSchema) cfg := redshiftavro.CreateConfig{ Schema: *schema, SortKeys: []string{"post_date", "title"}, IfNotExists: true, } statement, err := redshiftavro.CreateTableStatement(cfg) if err != nil { panic(err) } fmt.Println(statement) // CREATE TABLE IF NOT EXISTS posts( // ID INTEGER ENCODE LZO NOT NULL, // title VARCHAR(65535) ENCODE RAW NOT NULL, // body VARCHAR(65535) ENCODE ZSTD NOT NULL, // content_type VARCHAR(65535) ENCODE ZSTD NULL, // post_date TIMESTAMP WITHOUT TIME ZONE ENCODE RAW NOT NULL, // update_date TIMESTAMP WITHOUT TIME ZONE ENCODE LZO NULL, // reading_time_minutes DECIMAL(3,1) ENCODE RAW NULL // ) // SORTKEY( // post_date, // title // ) }
Output:
Types ¶
type CreateConfig ¶
type CreateConfig struct { Schema avro.RecordSchema SortKeys []string SortStyle SortStyle DistKey *string DistStyle DistStyle IfNotExists bool TableNameOverride string }
CreateConfig -
type RedshiftEncoding ¶
type RedshiftEncoding string
RedshiftEncoding -
const ( // ByteDict - ByteDict RedshiftEncoding = "BYTEDICT" // Delta - Delta RedshiftEncoding = "DELTA" // Delta32K - Delta32K RedshiftEncoding = "DELTA32K" // LZO - LZO RedshiftEncoding = "LZO" // Mostly8 - Mostly8 RedshiftEncoding = "MOSTLY8" // Mostly16 - Mostly16 RedshiftEncoding = "MOSTLY16" // Mostly32 - Mostly32 RedshiftEncoding = "MOSTLY32" // Raw - Raw RedshiftEncoding = "RAW" // RunLength - RunLength RedshiftEncoding = "RUNLENGTH" // Text255 - Text255 RedshiftEncoding = "TEXT255" // Text32K - Text32K RedshiftEncoding = "TEXT32K" // ZSTD - ZSTD RedshiftEncoding = "ZSTD" )
type RedshiftType ¶
type RedshiftType string
RedshiftType -
const ( // SmallInt - SmallInt RedshiftType = "SMALLINT" // Integer - Integer RedshiftType = "INTEGER" // BigInt - BigInt RedshiftType = "BIGINT" // Decimal - Decimal RedshiftType = "DECIMAL" // Real - Real RedshiftType = "REAL" // Double - Double RedshiftType = "DOUBLE" // Boolean - Boolean RedshiftType = "BOOLEAN" // Char - Char RedshiftType = "CHAR" // VarChar - VarChar RedshiftType = "VARCHAR" // Date - Date RedshiftType = "Date" // Timestamp - Timestamp RedshiftType = "TIMESTAMP" // Timestamptz - Timestamptz RedshiftType = "TIMESTAMPTZ" )
Click to show internal directories.
Click to hide internal directories.