-
Notifications
You must be signed in to change notification settings - Fork 183
[FLINK-34088] [hotfix] fix the problems with special table name characters of postgres and oracle and sqlserver. #89
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
base: main
Are you sure you want to change the base?
Changes from all commits
b13a3b9
f35971e
7272a79
b28197e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,10 +48,10 @@ void testInsertStatement() { | |
String insertStmt = dialect.getInsertIntoStatement(tableName, fieldNames); | ||
assertThat(insertStmt) | ||
.isEqualTo( | ||
"INSERT INTO tbl(id, name, email, ts, field1, field_2, __field_3__) " | ||
"INSERT INTO \"tbl\"(\"id\", \"name\", \"email\", \"ts\", \"field1\", \"field_2\", \"__field_3__\") " | ||
+ "VALUES (:id, :name, :email, :ts, :field1, :field_2, :__field_3__)"); | ||
NamedStatementMatcher.parsedSql( | ||
"INSERT INTO tbl(id, name, email, ts, field1, field_2, __field_3__) " | ||
"INSERT INTO \"tbl\"(\"id\", \"name\", \"email\", \"ts\", \"field1\", \"field_2\", \"__field_3__\") " | ||
Comment on lines
+51
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In issue description it was only something about table name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the method ‘quoteIdentifier’ is common,column metadata is also by call the method.Columns should have this problem as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we have a failing test reproducing the problem? |
||
+ "VALUES (?, ?, ?, ?, ?, ?, ?)") | ||
.parameter("id", singletonList(1)) | ||
.parameter("name", singletonList(2)) | ||
|
@@ -67,8 +67,10 @@ void testInsertStatement() { | |
void testDeleteStatement() { | ||
String deleteStmt = dialect.getDeleteStatement(tableName, keyFields); | ||
assertThat(deleteStmt) | ||
.isEqualTo("DELETE FROM tbl WHERE id = :id AND __field_3__ = :__field_3__"); | ||
NamedStatementMatcher.parsedSql("DELETE FROM tbl WHERE id = ? AND __field_3__ = ?") | ||
.isEqualTo( | ||
"DELETE FROM \"tbl\" WHERE \"id\" = :id AND \"__field_3__\" = :__field_3__"); | ||
NamedStatementMatcher.parsedSql( | ||
"DELETE FROM \"tbl\" WHERE \"id\" = ? AND \"__field_3__\" = ?") | ||
.parameter("id", singletonList(1)) | ||
.parameter("__field_3__", singletonList(2)) | ||
.matches(deleteStmt); | ||
|
@@ -78,8 +80,10 @@ void testDeleteStatement() { | |
void testRowExistsStatement() { | ||
String rowExistStmt = dialect.getRowExistsStatement(tableName, keyFields); | ||
assertThat(rowExistStmt) | ||
.isEqualTo("SELECT 1 FROM tbl WHERE id = :id AND __field_3__ = :__field_3__"); | ||
NamedStatementMatcher.parsedSql("SELECT 1 FROM tbl WHERE id = ? AND __field_3__ = ?") | ||
.isEqualTo( | ||
"SELECT 1 FROM \"tbl\" WHERE \"id\" = :id AND \"__field_3__\" = :__field_3__"); | ||
NamedStatementMatcher.parsedSql( | ||
"SELECT 1 FROM \"tbl\" WHERE \"id\" = ? AND \"__field_3__\" = ?") | ||
.parameter("id", singletonList(1)) | ||
.parameter("__field_3__", singletonList(2)) | ||
.matches(rowExistStmt); | ||
|
@@ -90,12 +94,12 @@ void testUpdateStatement() { | |
String updateStmt = dialect.getUpdateStatement(tableName, fieldNames, keyFields); | ||
assertThat(updateStmt) | ||
.isEqualTo( | ||
"UPDATE tbl SET id = :id, name = :name, email = :email, ts = :ts, " | ||
+ "field1 = :field1, field_2 = :field_2, __field_3__ = :__field_3__ " | ||
+ "WHERE id = :id AND __field_3__ = :__field_3__"); | ||
"UPDATE \"tbl\" SET \"id\" = :id, \"name\" = :name, \"email\" = :email, \"ts\" = :ts, " | ||
+ "\"field1\" = :field1, \"field_2\" = :field_2, \"__field_3__\" = :__field_3__ " | ||
+ "WHERE \"id\" = :id AND \"__field_3__\" = :__field_3__"); | ||
NamedStatementMatcher.parsedSql( | ||
"UPDATE tbl SET id = ?, name = ?, email = ?, ts = ?, field1 = ?, " | ||
+ "field_2 = ?, __field_3__ = ? WHERE id = ? AND __field_3__ = ?") | ||
"UPDATE \"tbl\" SET \"id\" = ?, \"name\" = ?, \"email\" = ?, \"ts\" = ?, \"field1\" = ?, " | ||
+ "\"field_2\" = ?, \"__field_3__\" = ? WHERE \"id\" = ? AND \"__field_3__\" = ?") | ||
.parameter("id", asList(1, 8)) | ||
.parameter("name", singletonList(2)) | ||
.parameter("email", singletonList(3)) | ||
|
@@ -112,18 +116,18 @@ void testUpsertStatement() { | |
assertThat(upsertStmt) | ||
.isEqualTo( | ||
" MERGE INTO tbl t " | ||
+ " USING (SELECT :id id, :name name, :email email, :ts ts, :field1 field1, :field_2 field_2, :__field_3__ __field_3__ FROM DUAL) s " | ||
+ " ON (t.id=s.id and t.__field_3__=s.__field_3__) " | ||
+ " WHEN MATCHED THEN UPDATE SET t.name=s.name, t.email=s.email, t.ts=s.ts, t.field1=s.field1, t.field_2=s.field_2" | ||
+ " WHEN NOT MATCHED THEN INSERT (id, name, email, ts, field1, field_2, __field_3__)" | ||
+ " VALUES (s.id, s.name, s.email, s.ts, s.field1, s.field_2, s.__field_3__)"); | ||
+ " USING (SELECT :id \"id\", :name \"name\", :email \"email\", :ts \"ts\", :field1 \"field1\", :field_2 \"field_2\", :__field_3__ \"__field_3__\" FROM DUAL) s " | ||
+ " ON (t.\"id\"=s.\"id\" and t.\"__field_3__\"=s.\"__field_3__\") " | ||
+ " WHEN MATCHED THEN UPDATE SET t.\"name\"=s.\"name\", t.\"email\"=s.\"email\", t.\"ts\"=s.\"ts\", t.\"field1\"=s.\"field1\", t.\"field_2\"=s.\"field_2\"" | ||
+ " WHEN NOT MATCHED THEN INSERT (\"id\", \"name\", \"email\", \"ts\", \"field1\", \"field_2\", \"__field_3__\")" | ||
+ " VALUES (s.\"id\", s.\"name\", s.\"email\", s.\"ts\", s.\"field1\", s.\"field_2\", s.\"__field_3__\")"); | ||
NamedStatementMatcher.parsedSql( | ||
" MERGE INTO tbl t " | ||
+ " USING (SELECT ? id, ? name, ? email, ? ts, ? field1, ? field_2, ? __field_3__ FROM DUAL) s " | ||
+ " ON (t.id=s.id and t.__field_3__=s.__field_3__) " | ||
+ " WHEN MATCHED THEN UPDATE SET t.name=s.name, t.email=s.email, t.ts=s.ts, t.field1=s.field1, t.field_2=s.field_2" | ||
+ " WHEN NOT MATCHED THEN INSERT (id, name, email, ts, field1, field_2, __field_3__)" | ||
+ " VALUES (s.id, s.name, s.email, s.ts, s.field1, s.field_2, s.__field_3__)") | ||
+ " USING (SELECT ? \"id\", ? \"name\", ? \"email\", ? \"ts\", ? \"field1\", ? \"field_2\", ? \"__field_3__\" FROM DUAL) s " | ||
+ " ON (t.\"id\"=s.\"id\" and t.\"__field_3__\"=s.\"__field_3__\") " | ||
+ " WHEN MATCHED THEN UPDATE SET t.\"name\"=s.\"name\", t.\"email\"=s.\"email\", t.\"ts\"=s.\"ts\", t.\"field1\"=s.\"field1\", t.\"field_2\"=s.\"field_2\"" | ||
+ " WHEN NOT MATCHED THEN INSERT (\"id\", \"name\", \"email\", \"ts\", \"field1\", \"field_2\", \"__field_3__\")" | ||
+ " VALUES (s.\"id\", s.\"name\", s.\"email\", s.\"ts\", s.\"field1\", s.\"field_2\", s.\"__field_3__\")") | ||
.parameter("id", singletonList(1)) | ||
.parameter("name", singletonList(2)) | ||
.parameter("email", singletonList(3)) | ||
|
@@ -139,11 +143,11 @@ void testSelectStatement() { | |
String selectStmt = dialect.getSelectFromStatement(tableName, fieldNames, keyFields); | ||
assertThat(selectStmt) | ||
.isEqualTo( | ||
"SELECT id, name, email, ts, field1, field_2, __field_3__ FROM tbl " | ||
+ "WHERE id = :id AND __field_3__ = :__field_3__"); | ||
"SELECT \"id\", \"name\", \"email\", \"ts\", \"field1\", \"field_2\", \"__field_3__\" FROM \"tbl\" " | ||
+ "WHERE \"id\" = :id AND \"__field_3__\" = :__field_3__"); | ||
NamedStatementMatcher.parsedSql( | ||
"SELECT id, name, email, ts, field1, field_2, __field_3__ FROM tbl " | ||
+ "WHERE id = ? AND __field_3__ = ?") | ||
"SELECT \"id\", \"name\", \"email\", \"ts\", \"field1\", \"field_2\", \"__field_3__\" FROM \"tbl\" " | ||
+ "WHERE \"id\" = ? AND \"__field_3__\" = ?") | ||
.parameter("id", singletonList(1)) | ||
.parameter("__field_3__", singletonList(2)) | ||
.matches(selectStmt); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't get why we are going to put logic with double quotes into some generic place if for different engines there could be different quotes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because oracle and postgres have the same escape characters, It's all double quotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this package is not only for oracle and postgres. E.g. MS SQL Server, MySQL are different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that the location of this method is not appropriate, I think it is OK, the specific escape characters of the data source in their own package implementation, there are public features to extract and did not find a better location