Documentation ¶
Overview ¶
Package internal implements database-agnostic functionality for HarbourBridge.
Index ¶
- func FixName(name string) (string, bool)
- func GenerateReport(driverName string, conv *Conv, w *bufio.Writer, badWrites map[string]int64) string
- func GetSpannerCol(conv *Conv, srcTable, srcCol string, mustExist bool) (string, error)
- func GetSpannerCols(conv *Conv, srcTable string, srcCols []string) ([]string, error)
- func GetSpannerTable(conv *Conv, srcTable string) (string, error)
- func Verbose() bool
- func VerboseInit(b bool)
- func VerbosePrintf(format string, a ...interface{})
- func VerbosePrintln(a ...interface{})
- type Conv
- func (conv *Conv) AddPrimaryKeys()
- func (conv *Conv) BadRows() int64
- func (conv *Conv) CollectBadRow(srcTable string, srcCols, vals []string)
- func (conv *Conv) DataMode() bool
- func (conv *Conv) DataStatement(stmtType string)
- func (conv *Conv) ErrorInStatement(stmtType string)
- func (conv *Conv) GetDDL(c ddl.Config) []string
- func (conv *Conv) Rows() int64
- func (conv *Conv) SampleBadRows(n int) []string
- func (conv *Conv) SchemaMode() bool
- func (conv *Conv) SchemaStatement(stmtType string)
- func (conv *Conv) SetDataMode()
- func (conv *Conv) SetDataSink(ds func(table string, cols []string, values []interface{}))
- func (conv *Conv) SetLocation(loc *time.Location)
- func (conv *Conv) SetSchemaMode()
- func (conv *Conv) SkipStatement(stmtType string)
- func (conv *Conv) StatementErrors() int64
- func (conv *Conv) Statements() int64
- func (conv *Conv) StatsAddBadRow(srcTable string, b bool)
- func (conv *Conv) StatsAddRow(srcTable string, b bool)
- func (conv *Conv) Unexpected(u string)
- func (conv *Conv) Unexpecteds() int64
- func (conv *Conv) WriteRow(srcTable, spTable string, spCols []string, spVals []interface{})
- type NameAndCols
- type Progress
- type Reader
- type SchemaIssue
- type SyntheticPKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FixName ¶
FixName maps a table_name, column_name or index_name into something spanner will accept. table_name, column_name or index_name must all adhere to the following regexp:
{a-z|A-Z}[{a-z|A-Z|0-9|_}+]
If the first character of the name is not allowed, we replace it by "A". We replace all other problem characters by "_". Returns a Spanner-acceptable name, and whether we had to change the name.
func GenerateReport ¶
func GenerateReport(driverName string, conv *Conv, w *bufio.Writer, badWrites map[string]int64) string
GenerateReport analyzes schema and data conversion stats and writes a detailed report to w and returns a brief summary (as a string).
func GetSpannerCol ¶
GetSpannerCol maps a source DB table/column into a legal Spanner column name. If mustExist is true, we return error if the column is new. Note that source DB column names can be essentially any string, but Spanner column names must use a limited character set. This means that getSpannerCol may have to change a name to make it legal, we must ensure that: a) the new col name is legal b) the new col name doesn't clash with other col names in the same table c) we consistently return the same name for the same col.
func GetSpannerCols ¶
GetSpannerCols maps a slice of source columns into their corresponding Spanner columns using GetSpannerCol.
func GetSpannerTable ¶
GetSpannerTable maps a source DB table name into a legal Spanner table name. Note that source DB column names can be essentially any string, but Spanner column names must use a limited character set. This means that getSpannerTable may have to change a name to make it legal, we must ensure that: a) the new table name is legal b) the new table name doesn't clash with other Spanner table names c) we consistently return the same name for this table.
func VerboseInit ¶
func VerboseInit(b bool)
VerboseInit determines whether verbose mode is enabled. Generally there should be one call to VerboseInit at startup.
func VerbosePrintf ¶
func VerbosePrintf(format string, a ...interface{})
VerbosePrintf prints to stdout if verbose is enabled.
func VerbosePrintln ¶
func VerbosePrintln(a ...interface{})
VerbosePrintln prints to stdout if verbose is enabled.
Types ¶
type Conv ¶
type Conv struct { SpSchema map[string]ddl.CreateTable // Maps Spanner table name to Spanner schema. SyntheticPKeys map[string]SyntheticPKey // Maps Spanner table name to synthetic primary key (if needed). SrcSchema map[string]schema.Table // Maps source-DB table name to schema information. Issues map[string]map[string][]SchemaIssue // Maps source-DB table/col to list of schema conversion issues. ToSpanner map[string]NameAndCols // Maps from source-DB table name to Spanner name and column mapping. ToSource map[string]NameAndCols // Maps from Spanner table name to source-DB table name and column mapping. Location *time.Location // Timezone (for timestamp conversion). Stats stats TimezoneOffset string // Timezone offset for timestamp conversion. // contains filtered or unexported fields }
Conv contains all schema and data conversion state.
func (*Conv) AddPrimaryKeys ¶
func (conv *Conv) AddPrimaryKeys()
AddPrimaryKeys analyzes all tables in conv.schema and adds synthetic primary keys for any tables that don't have primary key.
func (*Conv) BadRows ¶
BadRows returns the total count of bad rows encountered during data conversion.
func (*Conv) CollectBadRow ¶
CollectBadRow updates the list of bad rows, while respecting the byte limit for bad rows.
func (*Conv) DataStatement ¶
DataStatement increments the data statement stats for 'stmtType'.
func (*Conv) ErrorInStatement ¶
ErrorInStatement increments the error statement stats for 'stmtType'.
func (*Conv) GetDDL ¶
GetDDL Schema returns the Spanner schema that has been constructed so far. Return DDL in alphabetical table order.
func (*Conv) SampleBadRows ¶
SampleBadRows returns a string-formatted list of rows that generated errors. Returns at most n rows.
func (*Conv) SchemaMode ¶
SchemaMode returns true if conv is configured to schemaOnly.
func (*Conv) SchemaStatement ¶
SchemaStatement increments the schema statement stats for 'stmtType'.
func (*Conv) SetDataMode ¶
func (conv *Conv) SetDataMode()
SetDataMode configures conv to convert data and write it to Spanner. In this mode, we also do a complete re-processing of all statements for stats purposes (its hard to keep track of which stats are collected in each phase, so we simply reset and recollect), but we don't modify the schema.
func (*Conv) SetDataSink ¶
SetDataSink configures conv to use the specified data sink.
func (*Conv) SetLocation ¶
SetLocation configures the timezone for data conversion.
func (*Conv) SetSchemaMode ¶
func (conv *Conv) SetSchemaMode()
SetSchemaMode configures conv to process schema-related statements and build the Spanner schema. In schema mode we also process just enough of other statements to get an accurate count of the number of data rows (used for tracking progress when writing data to Spanner).
func (*Conv) SkipStatement ¶
SkipStatement increments the skip statement stats for 'stmtType'.
func (*Conv) StatementErrors ¶
StatementErrors returns the number of statement errors encountered.
func (*Conv) Statements ¶
Statements returns the total number of statements processed.
func (*Conv) StatsAddBadRow ¶
StatsAddBadRow increments the bad-row stats for 'srcTable' if b is true. See StatsAddRow comments for context.
func (*Conv) StatsAddRow ¶
StatsAddRow increments the count of rows for 'srcTable' if b is true. The boolean arg 'b' is used to avoid double counting of stats. Specifically, some code paths that report row stats run in both schema-mode and data-mode e.g. statement.go. To avoid double counting, we explicitly choose a mode-for-stats-collection for each place where row stats are collected. When specifying this mode take care to ensure that the code actually runs in the mode you specify, otherwise stats will be dropped.
func (*Conv) Unexpected ¶
Unexpected records stats about corner-cases and conditions that were not expected. Note that the counts maybe not be completely reliable due to potential double-counting because we process dump data twice.
func (*Conv) Unexpecteds ¶
Unexpecteds returns the total number of distinct unexpected conditions encountered during processing.
type NameAndCols ¶
NameAndCols contains the name of a table and its columns. Used to map between source DB and Spanner table and column names.
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress provides console progress functionality. i.e. it reports what percentage of a task is complete to the console, overwriting previous progress percentage with new progress.
func NewProgress ¶
NewProgress creates and returns a Progress instance.
func (*Progress) Done ¶
func (p *Progress) Done()
Done signals completion, and will report 100% if it hasn't already been reported.
func (*Progress) MaybeReport ¶
MaybeReport updates the state of p with the new 'progress' measure. If this update changes pct (integer part of percentage-done), MaybeReport will print out the new percentage, overwriting the previous percentage.
type Reader ¶
type Reader struct { LineNumber int // Starting at line 1 Offset int // Character offset from start of input. Starts with character 1. EOF bool // contains filtered or unexported fields }
Reader is a simple line-reader wrapper around bufio.Reader that provides line number, file offset, and cached eof state. Errors are printed (via fmt.Print) and then treated as eof.
type SchemaIssue ¶
type SchemaIssue int
SchemaIssue specifies a schema conversion issue.
const ( DefaultValue SchemaIssue = iota ForeignKey MissingPrimaryKey MultiDimensionalArray NoGoodType Numeric NumericThatFits Decimal DecimalThatFits Serial Timestamp Datetime Widened Time )
Defines all of the schema issues we track. Includes issues with type mappings, as well as features (such as source DB constraints) that aren't supported in Spanner.
type SyntheticPKey ¶
SyntheticPKey specifies a synthetic primary key and current sequence count for a table, if needed. We use a synthetic primary key when the source DB table has no primary key.