translator

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

* Copyright (C) 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License.

Index

Constants

View Source
const (
	STAR = "*"
)
View Source
const (
	SecondsInDay int64 = 86400
)

Variables

View Source
var (
	ErrEmptyTable           = errors.New("could not find table name to create spanner query")
	ErrParsingDelObj        = errors.New("error while parsing delete object")
	ErrParsingTs            = errors.New("timestamp could not be parsed")
	ErrTsNoValue            = errors.New("no value found for Timestamp")
	ErrEmptyTableOrKeyspace = errors.New("ToSpannerDelete: No table or keyspace name found in the query")
)

Functions

func NewCqlParser

func NewCqlParser(cqlQuery string, isDebug bool) (*cql.CqlParser, error)

Funtion to create lexer and parser object for the cql query

Types

type Clause

type Clause struct {
	Column       string
	Operator     string
	Value        string
	IsPrimaryKey bool
}

type ClauseResponse

type ClauseResponse struct {
	Clauses   []Clause
	Params    map[string]interface{}
	ParamKeys []string
}

type Column

type Column struct {
	Name        string
	SpannerType string
	CQLType     string
	ElementType string
}

type ColumnMeta

type ColumnMeta struct {
	Star   bool
	Column []tableConfig.SelectedColumns
}

type ColumnsResponse

type ColumnsResponse struct {
	Columns       []Column
	ValueArr      []string
	ParamKeys     []string
	PrimayColumns []string
}

type CreatetableQueryMap added in v1.0.1

type CreatetableQueryMap struct {
	CassandraQuery     string   // Original query string
	SpannerQuery       string   // Translated query string suitable for Spanner
	Table              string   // Table involved in the query
	Keyspace           string   // Keyspace to which the table belongs
	KeySpaceFlattening bool     // Boolean value to flatten the table name or not
	Columns            []Column // List of columns involved in the insert operation
	HasIfNotExists     bool     // Condition for IF NOT EXISTS checks
	PrimaryKeys        []string // Primary keys of the table
	TTLValue           int64    //timestamp
}

CreatetableQueryMap represents the mapping of an create query along with its translation details.

type DeleteQueryMap

type DeleteQueryMap struct {
	CassandraQuery    string                    // Original query string
	SpannerQuery      string                    // Translated query string suitable for Spanner
	QueryType         string                    // Type of the query (e.g., DELETE)
	Table             string                    // Table involved in the query
	Keyspace          string                    // Keyspace to which the table belongs
	Clauses           []Clause                  // List of clauses in the delete query
	Params            map[string]interface{}    // Parameters for the query
	ParamKeys         []string                  // Column names of the parameters
	PrimaryKeys       []string                  // Primary keys of the table
	ReturnMetadata    []*message.ColumnMetadata // Metadata of all columns of that table in Cassandra format
	VariableMetadata  []*message.ColumnMetadata // Metadata of variable columns for prepared queries in Cassandra format
	ExecuteByMutation bool                      // Flag to indicate if the delete should be executed by mutation
}

DeleteQueryMap represents the mapping of a delete query along with its translation details.

type InsertQueryMap

type InsertQueryMap struct {
	CassandraQuery   string                    // Original query string
	SpannerQuery     string                    // Translated query string suitable for Spanner
	QueryType        string                    // Type of the query (e.g., INSERT)
	Table            string                    // Table involved in the query
	Keyspace         string                    // Keyspace to which the table belongs
	Columns          []Column                  // List of columns involved in the insert operation
	Values           []interface{}             // Values to be inserted
	Params           map[string]interface{}    // Parameters for the query
	ParamKeys        []string                  // Column names of the parameters
	UsingTSCheck     string                    // Condition for using timestamp checks
	HasIfNotExists   bool                      // Condition for IF NOT EXISTS checks
	PrimaryKeys      []string                  // Primary keys of the table
	ReturnMetadata   []*message.ColumnMetadata // Metadata of all columns of that table in Cassandra format
	VariableMetadata []*message.ColumnMetadata // Metadata of variable columns for prepared queries in Cassandra format
}

InsertQueryMap represents the mapping of an insert query along with its translation details.

type Limit

type Limit struct {
	Count string
	// contains filtered or unexported fields
}

type OrderBy

type OrderBy struct {
	Column    string
	Operation string
	// contains filtered or unexported fields
}

type SelectQueryMap

type SelectQueryMap struct {
	CassandraQuery   string                               // Original query string
	SpannerQuery     string                               // Translated query string suitable for Spanner
	QueryType        string                               // Type of the query (e.g., SELECT)
	Table            string                               // Table involved in the query
	Keyspace         string                               // Keyspace to which the table belongs
	ColumnMeta       ColumnMeta                           // Translator generated Metadata about the columns involved
	Clauses          []Clause                             // List of clauses in the query
	Limit            Limit                                // Limit clause details
	OrderBy          OrderBy                              // Order by clause details
	Params           map[string]interface{}               // Parameters for the query
	ParamKeys        []string                             // column_name of the parameters
	AliasMap         map[string]tableConfig.AsKeywordMeta // Aliases used in the query
	PrimaryKeys      []string                             // Primary keys of the table
	ColumnsWithInOp  []string                             // Columns involved in IN operations
	ReturnMetadata   []*message.ColumnMetadata            // Metadata of selected columns in Cassandra format
	VariableMetadata []*message.ColumnMetadata            // Metadata of variable columns for prepared queries in Cassandra format
}

SelectQueryMap represents the mapping of a select query along with its translation details.

type TableObj

type TableObj struct {
	TableName    string
	KeyspaceName string
}

type Translator

type Translator struct {
	Logger          *zap.Logger
	TableConfig     *tableConfig.TableConfig
	KeyspaceFlatter bool
	UseRowTimestamp bool
	UseRowTTL       bool
	Debug           bool
}

func (*Translator) ToSpannerCreate added in v1.0.1

func (t *Translator) ToSpannerCreate(queryStr string, keyspaceFlatting bool, enableUsingTimestamp bool, enableUsingTTL bool) (*CreatetableQueryMap, error)

ToSpannerCreate converts a CQL CREATE TABLE query to a Spanner equivalent.

Parameters:

  • queryStr: The CQL CREATE TABLE query string.

Returns: A CreatetableQueryMap containing the original CQL query and the generated Spanner query, or an error if conversion fails.

func (*Translator) ToSpannerDelete

func (t *Translator) ToSpannerDelete(queryStr string) (*DeleteQueryMap, error)

ToSpannerDelete frames Spanner supported query for Delete Query

Parameters:

  • query: CQL Delete query

Returns: DeleteQueryMap struct and error if any

func (*Translator) ToSpannerSelect

func (t *Translator) ToSpannerSelect(originalQuery string) (*SelectQueryMap, error)

Translates Cassandra select statement into a compatible Cloud Spanner select query.

Parameters:

  • originalQuery: CQL Select statement

Returns: SelectQueryMap struct and error if any

func (*Translator) ToSpannerUpdate

func (t *Translator) ToSpannerUpdate(queryStr string) (*UpdateQueryMap, error)

ToSpannerUpdate frames Spanner supported query for Update Query

Parameters:

  • query: CQL Update query

Returns: UpdateQueryMap struct and error if any

func (*Translator) ToSpannerUpsert

func (t *Translator) ToSpannerUpsert(queryStr string) (*InsertQueryMap, error)

ToSpannerUpsert frames Spanner supported query for Insert Query

Parameters:

  • query: CQL Insert query

Returns: InsertQueryMap struct and error if any

type UpdateQueryMap

type UpdateQueryMap struct {
	CassandraQuery       string                    // Original query string
	SpannerQuery         string                    // Translated query string suitable for Spanner
	QueryType            string                    // Type of the query (e.g., UPDATE)
	Table                string                    // Table involved in the query
	Keyspace             string                    // Keyspace to which the table belongs
	UpdateSetValues      []UpdateSetValue          // Values to be updated
	Clauses              []Clause                  // List of clauses in the update query
	Params               map[string]interface{}    // Parameters for the query
	ParamKeys            []string                  // Column names of the parameters
	PrimaryKeys          []string                  // Primary keys of the table                   // Flag to indicate if local IDs pattern is used
	ReturnMetadata       []*message.ColumnMetadata // Metadata of all columns of that table in Cassandra format
	VariableMetadata     []*message.ColumnMetadata // Metadata of variable columns for prepared queries in Cassandra format
	SelectQueryMapUpdate string                    // Select query to pull the map information to update the specific key/value
	MapUpdateColumn      string                    // Column name to update map based on key/value.
}

Update Query Map UpdateQueryMap represents the mapping of an update query along with its translation details.

type UpdateSetResponse

type UpdateSetResponse struct {
	UpdateSetValues []UpdateSetValue
	ParamKeys       []string
	Params          map[string]interface{}
	MapUpdateColumn string
}

type UpdateSetValue

type UpdateSetValue struct {
	Column           string
	Value            string
	IsMapUpdateByKey bool
	MapUpdateKey     string
	RawValue         interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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