redshiftsql

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TiDB2RedshiftTypeMap map[string]string = map[string]string{
	"text":       "TEXT",
	"tinytext":   "TEXT",
	"mediumtext": "TEXT",
	"longtext":   "TEXT",
	"blob":       "VARBYTE",
	"tinyblob":   "VARBYTE",

	"varchar":            "VARCHAR",
	"char":               "CHAR",
	"binary":             "VARBYTE",
	"varbinary":          "VARBYTE",
	"tinyint":            "SMALLINT",
	"tinyint unsigned":   "SMALLINT",
	"smallint":           "SMALLINT",
	"smallint unsigned":  "INT",
	"int":                "INT",
	"int unsigned":       "BIGINT",
	"mediumint":          "INT",
	"mediumint unsigned": "BIGINT",
	"bigint":             "BIGINT",
	"bigint unsigned":    "DECIMAL(20,0)",
	"float":              "REAL",
	"float unsigned":     "REAL",
	"double":             "DOUBLE PRECISION",
	"double unsigned":    "DOUBLE PRECISION",
	"decimal":            "DECIMAL",
	"numeric":            "NUMERIC",
	"bool":               "BOOLEAN",
	"boolean":            "BOOLEAN",
	"date":               "DATE",
	"datetime":           "TIMESTAMP",
	"timestamp":          "TIMESTAMP",
	"time":               "TIME",
}

TiDB2RedshiftTypeMap is a map from TiDB type to Redshift type.

Functions

func CreateIncrementalTable added in v0.0.4

func CreateIncrementalTable(db *sql.DB, columns []cloudstorage.TableCol, tableName string) error

CreateIncrementalTable create a temp table to store incremental data Note: We do not use external table here, because redshift external table has a lot of limitations: 1. Does not support NOT NULL or PRIMARY KEY 2. Does not support specifying null value 3. Need a manifest file to specify the file location 4. ...

func CreateSchema

func CreateSchema(db *sql.DB, schemaName string) error

func CreateTable

func CreateTable(sourceDatabase string, sourceTable string, sourceTiDBConn, redConn *sql.DB) error

func DeleteQuery

func DeleteQuery(db *sql.DB, tableDef cloudstorage.TableDefinition, incurmentalTableName string) error

func DropTableIfExists added in v0.0.4

func DropTableIfExists(db *sql.DB, tableName string) error

func GenDDLViaColumnsDiff

func GenDDLViaColumnsDiff(prevColumns []cloudstorage.TableCol, curTableDef cloudstorage.TableDefinition) ([]string, error)

func GetRedshiftColumnString

func GetRedshiftColumnString(column cloudstorage.TableCol) (string, error)

GetRedshiftColumnString returns a string describing the column in Redshift, e.g. "id INT NOT NULL DEFAULT '0'" Refer to: https://dev.mysql.com/doc/refman/8.0/en/data-types.html https://docs.aws.amazon.com/redshift/latest/dg/c_Supported_data_types.html

func GetRedshiftTypeString

func GetRedshiftTypeString(column cloudstorage.TableCol) (string, error)

GetRedshiftColumnString returns the column string for Redshift. For example, "id INT", "name VARCHAR(255) and "age INT".

func InsertQuery

func InsertQuery(db *sql.DB, tableDef cloudstorage.TableDefinition, incurmentalTableName string) error

func LoadSnapshotFromS3

func LoadSnapshotFromS3(db *sql.DB, targetTable, filePath string, credential *credentials.Value) error

LoadSnapshotFromS3 load snapshot data from s3 to redshift use csv file path for storageUri, like s3://tidbbucket/snapshot/stock.csv

Types

type RedshiftConfig

type RedshiftConfig struct {
	Host     string
	Port     int
	User     string
	Pass     string
	Database string
	Schema   string
}

func (*RedshiftConfig) OpenDB

func (config *RedshiftConfig) OpenDB() (*sql.DB, error)

Open a connection to Redshift. can not specify one schema in redshift

type RedshiftConnector

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

func NewRedshiftConnector

func NewRedshiftConnector(rsConfig *RedshiftConfig, increTableName string, storageURI *url.URL, s3Credentials *credentials.Value) (*RedshiftConnector, error)

func (*RedshiftConnector) Close

func (rc *RedshiftConnector) Close()

func (*RedshiftConnector) CopyTableSchema

func (rc *RedshiftConnector) CopyTableSchema(sourceDatabase string, sourceTable string, sourceTiDBConn *sql.DB) error

func (*RedshiftConnector) ExecDDL

func (rc *RedshiftConnector) ExecDDL(tableDef cloudstorage.TableDefinition) error

func (*RedshiftConnector) InitSchema

func (rc *RedshiftConnector) InitSchema(columns []cloudstorage.TableCol) error

func (*RedshiftConnector) LoadIncrement

func (rc *RedshiftConnector) LoadIncrement(tableDef cloudstorage.TableDefinition, filePath string) error

func (*RedshiftConnector) LoadSnapshot

func (rc *RedshiftConnector) LoadSnapshot(targetTable, filePath string) error

Jump to

Keyboard shortcuts

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