Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use full table name in query #39

Merged
merged 1 commit into from
Oct 14, 2024
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
2 changes: 1 addition & 1 deletion internal/dst_table/dst_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (dstTable *DstTable) Init(ctx context.Context) error {
}
metaInfo := NewTableMetaInfo()
metaInfo.PrimaryKey = desc.PrimaryKey
metaInfo.Name = desc.Name
metaInfo.Name = dstTable.tablePath
for _, column := range desc.Columns {
metaInfo.Columns[column.Name] = column
xlog.Debug(ctx, "Column type", zap.String("col_name", column.Name), zap.String("type", column.Type.String()))
Expand Down
4 changes: 2 additions & 2 deletions internal/dst_table/gen_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func GenQueryFromUpdateTx(ctx context.Context, tableMetaInfo TableMetaInfo, txDa
if len(txData[0].ColumnValues) > 0 {
allColumns += ", " + txData[0].ColumnsString
}
result.Statement = "UPSERT INTO " + tableMetaInfo.Name + " (" + allColumns + ") SELECT " + allColumns + " FROM AS_TABLE(" + pName + ");\n"
result.Statement = "UPSERT INTO `" + tableMetaInfo.Name + "` (" + allColumns + ") SELECT " + allColumns + " FROM AS_TABLE(" + pName + ");\n"
param, err := GenListParam(ctx, tableMetaInfo, txData)
if err != nil {
xlog.Error(ctx, "Unable to gen list param", zap.Error(err))
Expand All @@ -369,7 +369,7 @@ func GenQueryFromUpdateTx(ctx context.Context, tableMetaInfo TableMetaInfo, txDa
func GenQueryFromEraseTx(ctx context.Context, tableMetaInfo TableMetaInfo, txData []UpdatingData, localStatementNum int, globalStatementNum int) (QueryStatement, error) {
result := NewQueryStatement()
pName := "$p_" + string(fmt.Sprint(globalStatementNum)) + "_" + string(fmt.Sprint(localStatementNum))
result.Statement = "DELETE FROM " + tableMetaInfo.Name + " ON SELECT * FROM AS_TABLE(" + pName + ");\n"
result.Statement = "DELETE FROM `" + tableMetaInfo.Name + "` ON SELECT * FROM AS_TABLE(" + pName + ");\n"
param, err := GenListParam(ctx, tableMetaInfo, txData)
if err != nil {
xlog.Error(ctx, "Unable to gen list param", zap.Error(err))
Expand Down
18 changes: 9 additions & 9 deletions internal/dst_table/gen_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestGenUpdateQuery(t *testing.T) {
txData2, _ := reader.ParseTxData(ctx, []byte("{\"update\":{\"value1\":\"15\", \"value3\":1.00000009},\"key\":[16,\"16\"],\"ts\":[18446744073709551614,18446744073709551614]}"), 0)
query, err := GenQueryFromUpdateTx(ctx, GetTestTableMetaInfo(), []UpdatingData{CreateData(txData1), CreateData(txData2)}, 0, 1)
require.Nil(t, err)
assert.Equal(t, "UPSERT INTO path (`key1`, `key2`, `value1`, `value2`, `value3`, `value4`) SELECT `key1`, `key2`, `value1`, `value2`, `value3`, `value4` FROM AS_TABLE($p_1_0);\n", query.Statement)
assert.Equal(t, "UPSERT INTO `path` (`key1`, `key2`, `value1`, `value2`, `value3`, `value4`) SELECT `key1`, `key2`, `value1`, `value2`, `value3`, `value4` FROM AS_TABLE($p_1_0);\n", query.Statement)
assert.Equal(t, len(query.Params), 1)
assert.Equal(t, query.Params[0].Name(), "$p_1_0")
expectedParams := "[" +
Expand All @@ -76,7 +76,7 @@ func TestGenEraseQuery(t *testing.T) {
txData2, _ := reader.ParseTxData(ctx, []byte("{\"erase\":{},\"key\":[16,\"16\"],\"ts\":[18446744073709551614,18446744073709551614]}"), 0)
query, err := GenQueryFromEraseTx(ctx, GetTestTableMetaInfo(), []UpdatingData{CreateData(txData1), CreateData(txData2)}, 1, 1)
require.Nil(t, err)
assert.Equal(t, "DELETE FROM path ON SELECT * FROM AS_TABLE($p_1_1);\n", query.Statement)
assert.Equal(t, "DELETE FROM `path` ON SELECT * FROM AS_TABLE($p_1_1);\n", query.Statement)
assert.Equal(t, len(query.Params), 1)
assert.Equal(t, query.Params[0].Name(), "$p_1_1")
expectedParams := "[" +
Expand All @@ -98,9 +98,9 @@ func TestGenQuery(t *testing.T) {
txData8, _ := reader.ParseTxData(ctx, []byte("{\"update\":{\"value1\":\"27\", \"value3\":1.00000009},\"key\":[17,\"17\"],\"ts\":[18446744073709551613,18446744073709551613]}"), 0)
query, err := GenQuery(ctx, GetTestTableMetaInfo(), []types.TxData{txData1, txData2, txData3, txData4, txData5, txData6, txData7, txData8}, 0)
require.Nil(t, err)
expectedResult := "UPSERT INTO path (`key1`, `key2`, `value1`, `value2`, `value3`, `value4`) SELECT `key1`, `key2`, `value1`, `value2`, `value3`, `value4` FROM AS_TABLE($p_0_0);\n" +
"UPSERT INTO path (`key1`, `key2`, `value1`, `value3`) SELECT `key1`, `key2`, `value1`, `value3` FROM AS_TABLE($p_0_1);\n" +
"DELETE FROM path ON SELECT * FROM AS_TABLE($p_0_2);\n"
expectedResult := "UPSERT INTO `path` (`key1`, `key2`, `value1`, `value2`, `value3`, `value4`) SELECT `key1`, `key2`, `value1`, `value2`, `value3`, `value4` FROM AS_TABLE($p_0_0);\n" +
"UPSERT INTO `path` (`key1`, `key2`, `value1`, `value3`) SELECT `key1`, `key2`, `value1`, `value3` FROM AS_TABLE($p_0_1);\n" +
"DELETE FROM `path` ON SELECT * FROM AS_TABLE($p_0_2);\n"
assert.Equal(t, expectedResult, query.Query)
expectedParams := "{" +
"\"$p_0_0\":" +
Expand Down Expand Up @@ -130,8 +130,8 @@ func TestGenOnlyUpsertQuery(t *testing.T) {
txData5, _ := reader.ParseTxData(ctx, []byte("{\"update\":{\"value1\":\"27\", \"value3\":1.00000009},\"key\":[17,\"17\"],\"ts\":[18446744073709551613,18446744073709551613]}"), 0)
query, err := GenQuery(ctx, GetTestTableMetaInfo(), []types.TxData{txData1, txData2, txData3, txData4, txData5}, 0)
require.Nil(t, err)
expectedResult := "UPSERT INTO path (`key1`, `key2`, `value1`, `value2`, `value3`, `value4`) SELECT `key1`, `key2`, `value1`, `value2`, `value3`, `value4` FROM AS_TABLE($p_0_0);\n" +
"UPSERT INTO path (`key1`, `key2`, `value1`, `value3`) SELECT `key1`, `key2`, `value1`, `value3` FROM AS_TABLE($p_0_1);\n"
expectedResult := "UPSERT INTO `path` (`key1`, `key2`, `value1`, `value2`, `value3`, `value4`) SELECT `key1`, `key2`, `value1`, `value2`, `value3`, `value4` FROM AS_TABLE($p_0_0);\n" +
"UPSERT INTO `path` (`key1`, `key2`, `value1`, `value3`) SELECT `key1`, `key2`, `value1`, `value3` FROM AS_TABLE($p_0_1);\n"
assert.Equal(t, expectedResult, query.Query)
expectedParams := "{" +
"\"$p_0_0\":" +
Expand All @@ -155,7 +155,7 @@ func TestGenOnlyEraseQuery(t *testing.T) {
txData3, _ := reader.ParseTxData(ctx, []byte("{\"erase\":{},\"key\":[16,\"16\"],\"ts\":[18446744073709551614,18446744073709551614]}"), 0)
query, err := GenQuery(ctx, GetTestTableMetaInfo(), []types.TxData{txData1, txData2, txData3}, 0)
require.Nil(t, err)
expectedResult := "DELETE FROM path ON SELECT * FROM AS_TABLE($p_0_0);\n"
expectedResult := "DELETE FROM `path` ON SELECT * FROM AS_TABLE($p_0_0);\n"
assert.Equal(t, expectedResult, query.Query)
expectedParams := "{\"$p_0_0\":" +
"[" +
Expand All @@ -170,7 +170,7 @@ func TestGenQueryWithTimestamp(t *testing.T) {
txData1, _ := reader.ParseTxData(ctx, []byte("{\"update\":{\"value1\":\"15\", \"value5\":\"1970-01-01T00:00:01.000001Z\"},\"key\":[15,\"15\"],\"ts\":[18446744073709551615,18446744073709551615]}"), 0)
query, err := GenQueryFromUpdateTx(ctx, GetTestTableMetaInfo(), []UpdatingData{CreateData(txData1)}, 0, 1)
require.Nil(t, err)
assert.Equal(t, "UPSERT INTO path (`key1`, `key2`, `value1`, `value5`) SELECT `key1`, `key2`, `value1`, `value5` FROM AS_TABLE($p_1_0);\n", query.Statement)
assert.Equal(t, "UPSERT INTO `path` (`key1`, `key2`, `value1`, `value5`) SELECT `key1`, `key2`, `value1`, `value5` FROM AS_TABLE($p_1_0);\n", query.Statement)
assert.Equal(t, len(query.Params), 1)
assert.Equal(t, query.Params[0].Name(), "$p_1_0")
expectedParams := "[" +
Expand Down
Loading