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
- Variables
- func NewCqlParser(cqlQuery string, isDebug bool) (*cql.CqlParser, error)
- type Clause
- type ClauseResponse
- type Column
- type ColumnMeta
- type ColumnsResponse
- type CreatetableQueryMap
- type DeleteQueryMap
- type InsertQueryMap
- type Limit
- type OrderBy
- type SelectQueryMap
- type TableObj
- type Translator
- func (t *Translator) ToSpannerCreate(queryStr string, keyspaceFlatting bool, enableUsingTimestamp bool, ...) (*CreatetableQueryMap, error)
- func (t *Translator) ToSpannerDelete(queryStr string) (*DeleteQueryMap, error)
- func (t *Translator) ToSpannerSelect(originalQuery string) (*SelectQueryMap, error)
- func (t *Translator) ToSpannerUpdate(queryStr string) (*UpdateQueryMap, error)
- func (t *Translator) ToSpannerUpsert(queryStr string) (*InsertQueryMap, error)
- type UpdateQueryMap
- type UpdateSetResponse
- type UpdateSetValue
Constants ¶
const (
STAR = "*"
)
const (
SecondsInDay int64 = 86400
)
Variables ¶
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 ¶
Types ¶
type ClauseResponse ¶
type ColumnMeta ¶
type ColumnMeta struct { Star bool Column []tableConfig.SelectedColumns }
type ColumnsResponse ¶
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 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 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 }