-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
query should be able to filter by whole family and cherry pickable ta…
…bles
- Loading branch information
Hongyu Zhou
committed
Feb 26, 2024
1 parent
5dffcef
commit 3d90f7f
Showing
3 changed files
with
120 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,22 +130,34 @@ func (source *sqlDmlSource) Next(ctx context.Context) (statement schema.DMLState | |
|
||
// Helper function to generate the SQL query | ||
func generateSQLQuery(ledgerTableName, shardingFamily, shardingTable string, blocksize int) string { | ||
baseQuery := "SELECT seq, leader_ts, statement, family_name, table_name FROM $1 WHERE " | ||
whereClause := "seq > ?" | ||
limitClause := " ORDER BY seq LIMIT $4" | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
janderson-seg
Contributor
|
||
if shardingFamily != "" { | ||
familiesStr := prepareString(shardingFamily) | ||
tablesStr := prepareString(shardingTable) | ||
return sqlgen.SqlSprintf("SELECT seq, leader_ts, statement, family_name, table_name FROM $1 WHERE seq > ? AND family_name IN $2 AND CONCAT(family_name,'___',table_name) IN $3 ORDER BY seq LIMIT $4", | ||
ledgerTableName, | ||
familiesStr, | ||
tablesStr, | ||
fmt.Sprintf("%d", blocksize)) | ||
} else { | ||
return sqlgen.SqlSprintf("SELECT seq, leader_ts, statement, family_name, table_name FROM $1 WHERE seq > ? ORDER BY seq LIMIT $2", | ||
ledgerTableName, | ||
fmt.Sprintf("%d", blocksize)) | ||
whereClause += fmt.Sprintf(" AND family_name IN $2") | ||
} | ||
|
||
if shardingTable != "" { | ||
whereClause += fmt.Sprintf(" AND CONCAT(family_name,'___',table_name) IN $3") | ||
} | ||
|
||
if shardingFamily != "" && shardingTable != "" { | ||
whereClause = fmt.Sprintf("seq > ? AND (family_name IN $2 OR CONCAT(family_name,'___',table_name) IN $3)") | ||
} | ||
|
||
return sqlgen.SqlSprintf(baseQuery+whereClause+limitClause, | ||
ledgerTableName, | ||
prepareString(shardingFamily), | ||
prepareString(shardingTable), | ||
fmt.Sprintf("%d", blocksize)) | ||
} | ||
|
||
// Helper function to prepare the family string for SQL query | ||
func prepareString(str string) string { | ||
if str == "" { | ||
return "" | ||
} | ||
|
||
return "(\"" + strings.ReplaceAll(str, ",", "\", \"") + "\")" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Having tables for families already specified might confuse future users.