Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions flags_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,28 @@ func TestValidateExecutionOptions(t *testing.T) {
mode: partitionedDML{},
err: "--strong cannot be combined with --enable-partitioned-dml",
},
{
name: "partitioned_dml_rejects_non_dml",
o: opts{EnablePartitionedDML: true},
mode: single{spanner.StrongRead()},
err: "--enable-partitioned-dml can only be used with DML statements",
},
{
name: "jq_lazy_allows_read_write_dml",
o: opts{JqInputMode: "lazy"},
mode: readWrite{},
},
{
name: "partitioned_dml_allows_eager",
o: opts{EnablePartitionedDML: true, JqInputMode: "eager"},
mode: partitionedDML{},
},
{
name: "partitioned_dml_rejects_lazy",
o: opts{EnablePartitionedDML: true, JqInputMode: "lazy"},
mode: partitionedDML{},
err: "--jq-input-mode=lazy is not supported for partitioned DML",
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -303,6 +325,20 @@ func TestQueryModeForQuery(t *testing.T) {
{name: "dml_with_comment", query: "-- c\nUPDATE T SET X=1", partitionedEnabled: false, tb: tb, wantMode: "readWrite"},
{name: "partitioned_dml", query: "UPDATE T SET X=1", partitionedEnabled: true, tb: tb, wantMode: "partitionedDML"},
{name: "normal_query", query: "SELECT 1", partitionedEnabled: false, tb: candidateTimestamp, wantMode: "single"},
{
name: "partitioned_flag_with_select",
query: "SELECT 1",
partitionedEnabled: true,
tb: candidateTimestamp,
wantMode: "single",
},
{
name: "partitioned_flag_with_ddl",
query: "CREATE TABLE T (K INT64) PRIMARY KEY (K)",
partitionedEnabled: true,
tb: tb,
wantMode: "single",
},
}

for _, tt := range tests {
Expand Down
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ func isReadWriteStatement(query string) bool {
}

func queryModeForQuery(query string, enablePartitionedDML bool, tb spanner.TimestampBound) queryMode {
if enablePartitionedDML {
return partitionedDML{}
}
if isReadWriteStatement(query) {
if enablePartitionedDML {
return partitionedDML{}
}
return readWrite{}
}
return single{tb}
Expand All @@ -215,6 +215,14 @@ func validateExecutionOptions(o opts, mode queryMode) error {
return fmt.Errorf("%s cannot be used with DML statements", flagName)
}
}
if o.EnablePartitionedDML {
if _, ok := mode.(partitionedDML); !ok {
return fmt.Errorf("--enable-partitioned-dml can only be used with DML statements")
}
}
if _, ok := mode.(partitionedDML); ok && o.JqInputMode == "lazy" {
return fmt.Errorf("--jq-input-mode=lazy is not supported for partitioned DML")
}
return nil
}

Expand Down
Loading