Skip to content

feat: support DML with Returning clause in Connection API #1978

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
55ae7db
feat: incorporate dml with returning clause
rajatbhatta Aug 17, 2022
f20d02f
feat: changes
rajatbhatta Aug 17, 2022
e06d436
feat: change handling of AsyncResultSet.
rajatbhatta Aug 17, 2022
bfbacfa
fix: lint
rajatbhatta Aug 17, 2022
3807e5f
doc: add comments
rajatbhatta Aug 17, 2022
595ee17
fix: lint
rajatbhatta Aug 17, 2022
f1326ff
test: add tests for executeBatchUpdate
rajatbhatta Aug 19, 2022
3f069bd
test: import fix
rajatbhatta Aug 19, 2022
ba692dc
test: remove redundant import
rajatbhatta Aug 19, 2022
ff3c0ff
test: add abort tests for dml returning
rajatbhatta Aug 19, 2022
5d1c0e5
test: add pg dml returning tests
rajatbhatta Aug 22, 2022
edaad92
feat: change error statement
rajatbhatta Aug 22, 2022
24cf255
doc: add doc for dml with returning clause usage
rajatbhatta Aug 22, 2022
3284f66
Merge branch 'googleapis:main' into dml-returning-parsing-changes
rajatbhatta Aug 22, 2022
4024412
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/co…
rajatbhatta Aug 23, 2022
4ae2f8d
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/co…
rajatbhatta Aug 23, 2022
c601a50
fix: incorporate review comments
rajatbhatta Aug 23, 2022
14e741f
test: add more test cases
rajatbhatta Aug 23, 2022
64422eb
test: add todo
rajatbhatta Aug 23, 2022
82e35fe
test: add separate abort tests for dml returning
rajatbhatta Aug 23, 2022
a7db0c1
fix: add try-with-resources block around ResultSet
rajatbhatta Aug 23, 2022
cc00396
feat: enhancement by adding a pre-check
rajatbhatta Aug 24, 2022
c093b9b
feat: changes
rajatbhatta Aug 24, 2022
4af9cbe
test: delete unnecessary test
rajatbhatta Aug 24, 2022
9f59715
test: add few more tests to PG parser
rajatbhatta Aug 24, 2022
218c3b7
feat: method doc update
rajatbhatta Aug 25, 2022
ea4152f
test: nit fixes
rajatbhatta Aug 26, 2022
e2a463e
feat: handle another corner case
rajatbhatta Aug 30, 2022
60fcb4c
test: add another test
rajatbhatta Aug 30, 2022
2c862c4
Merge branch 'main' into dml-returning-parsing-changes
rajatbhatta Nov 9, 2022
58d0278
clirr fixes
rajatbhatta Nov 9, 2022
81b7908
revert env for integration tests
rajatbhatta Nov 9, 2022
d0e173d
remove comments
rajatbhatta Nov 9, 2022
9e15159
skip returning tests in emulator
rajatbhatta Nov 9, 2022
ac3ea4f
fix: linting
rajatbhatta Nov 9, 2022
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
Prev Previous commit
Next Next commit
test: nit fixes
  • Loading branch information
rajatbhatta committed Aug 26, 2022
commit ea4152fe0fe89581d8cd0eacbc95769bedbd045d
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ static int countOccurrencesOf(char c, String string) {
* @return A boolean indicating whether the sql string has a Returning clause or not.
*/
@InternalApi
abstract boolean checkReturningClauseInternal(String sql);
abstract protected boolean checkReturningClauseInternal(String sql);

@InternalApi
public boolean checkReturningClause(String sql) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
public class PostgreSQLStatementParser extends AbstractStatementParser {
private static final Pattern RETURNING_PATTERN = Pattern.compile("[ ')\"]returning[ '(\"]");
private static final Pattern AS_RETURNING_PATTERN = Pattern.compile("[ ')\"]as returning[ '(\"]");
private static final String RETURNING_STRING = "returning";

PostgreSQLStatementParser() throws CompileException {
super(
Expand Down Expand Up @@ -305,12 +306,12 @@ private boolean isReturning(String sql, int index) {

@InternalApi
@Override
boolean checkReturningClauseInternal(String rawSql) {
protected boolean checkReturningClauseInternal(String rawSql) {
Preconditions.checkNotNull(rawSql);
String sql = rawSql.toLowerCase();
// Do a pre-check to check if the SQL string definitely does not have a returning clause.
// If this check fails, do a more involved check to check for a returning clause.
if (!sql.contains("returning")) {
if (!sql.contains(RETURNING_STRING)) {
return false;
}
sql = sql.replaceAll("\\s+", " ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
@InternalApi
public class SpannerStatementParser extends AbstractStatementParser {

final Pattern THEN_RETURN_PATTERN = Pattern.compile("[ `')\"]then return[ `'(\"]");
private static final Pattern THEN_RETURN_PATTERN = Pattern.compile("[ `')\"]then return[ `'(\"]");
private static final String THEN_STRING = "then";
private static final String RETURN_STRING = "return";

public SpannerStatementParser() throws CompileException {
super(
Expand Down Expand Up @@ -280,12 +282,12 @@ private boolean isReturning(String sql, int index) {

@InternalApi
@Override
boolean checkReturningClauseInternal(String rawSql) {
protected boolean checkReturningClauseInternal(String rawSql) {
Preconditions.checkNotNull(rawSql);
String sql = rawSql.toLowerCase();
// Do a pre-check to check if the SQL string definitely does not have a returning clause.
// If this check fails, do a more involved check to check for a returning clause.
if (!(sql.contains("then") && sql.contains("return"))) {
if (!(sql.contains(THEN_STRING) && sql.contains(RETURN_STRING))) {
return false;
}
sql = sql.replaceAll("\\s+", " ");
Expand Down