Skip to content

Commit

Permalink
gemini: invalid materialized view ddl fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrik Johansson committed Jul 5, 2019
1 parent 0dfdaeb commit 773f004
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func GenSchema(sc SchemaConfig) *Schema {
}

var mvs []MaterializedView
if sc.CQLFeature > CQL_FEATURE_BASIC {
if sc.CQLFeature > CQL_FEATURE_BASIC && numClusteringKeys > 0 {
mvs = createMaterializedViews(partitionKeys, clusteringKeys, columns)
}

Expand Down Expand Up @@ -465,19 +465,11 @@ func (s *Schema) GetCreateSchema() []string {
} else {
createMaterializedView = "CREATE MATERIALIZED VIEW %s.%s AS SELECT * FROM %s.%s WHERE %s PRIMARY KEY ((%s)"
}
if len(mvClusteringKeys) > 0 {
createMaterializedView = createMaterializedView + ",%s)"
stmts = append(stmts, fmt.Sprintf(createMaterializedView,
s.Keyspace.Name, mv.Name, s.Keyspace.Name, t.Name,
strings.Join(mvPrimaryKeysNotNull, " AND "),
strings.Join(mvPartitionKeys, ","), strings.Join(t.ClusteringKeys.Names(), ",")))
} else {
createMaterializedView = createMaterializedView + ")"
stmts = append(stmts, fmt.Sprintf(createMaterializedView,
s.Keyspace.Name, mv.Name, s.Keyspace.Name, t.Name,
strings.Join(mvPrimaryKeysNotNull, " AND "),
strings.Join(mvPartitionKeys, ",")))
}
createMaterializedView = createMaterializedView + ",%s)"
stmts = append(stmts, fmt.Sprintf(createMaterializedView,
s.Keyspace.Name, mv.Name, s.Keyspace.Name, t.Name,
strings.Join(mvPrimaryKeysNotNull, " AND "),
strings.Join(mvPartitionKeys, ","), strings.Join(t.ClusteringKeys.Names(), ",")))
}
}
return stmts
Expand Down

0 comments on commit 773f004

Please sign in to comment.