-
Notifications
You must be signed in to change notification settings - Fork 26
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
refactor: use analyze to get statement params #478
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f63eaf4
refactor: use analyze to get statement params
olavloite 9331597
feat: use analyze to describe statements
olavloite bf65274
Merge branch 'postgresql-dialect' into analyze-params
olavloite 2f1185a
fix: get param index from param name instead of index in list
olavloite 6192233
test: add more tests
olavloite 9a5aa98
test: add more tests + disable clirr
olavloite 0b32f77
chore: cleanup
olavloite a362e7e
Merge branch 'postgresql-dialect' into analyze-params
olavloite 6ce5183
fix: update test for analyzeUpdate
olavloite bc9021b
fix: disable flaky assertion
olavloite 2287d60
fix: remove accidentally committed folder
olavloite 216ab1c
fix: remove more assertions pending node-postgres 8.9
olavloite fed8735
fix: disable more assertions awaiting 8.9
olavloite ec21906
Merge branch 'postgresql-dialect' into analyze-params
olavloite 4c29f55
Merge branch 'postgresql-dialect' into analyze-params
olavloite 9519837
Merge branch 'postgresql-dialect' into analyze-params
olavloite 3d04155
Merge branch 'postgresql-dialect' into analyze-params
olavloite fcd05a3
Merge branch 'postgresql-dialect' into analyze-params
olavloite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
28 changes: 0 additions & 28 deletions
28
src/main/java/com/google/cloud/spanner/pgadapter/metadata/DescribeMetadata.java
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
src/main/java/com/google/cloud/spanner/pgadapter/metadata/DescribePortalMetadata.java
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
src/main/java/com/google/cloud/spanner/pgadapter/metadata/DescribeResult.java
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.cloud.spanner.pgadapter.metadata; | ||
|
||
import com.google.api.core.InternalApi; | ||
import com.google.cloud.spanner.ResultSet; | ||
import com.google.cloud.spanner.pgadapter.error.PGExceptionFactory; | ||
import com.google.cloud.spanner.pgadapter.error.SQLState; | ||
import com.google.cloud.spanner.pgadapter.parsers.Parser; | ||
import com.google.spanner.v1.StructType; | ||
import java.util.Arrays; | ||
|
||
@InternalApi | ||
public class DescribeResult { | ||
private final ResultSet resultSet; | ||
private final int[] parameters; | ||
|
||
public DescribeResult(int[] givenParameterTypes, ResultSet resultMetadata) { | ||
this.resultSet = resultMetadata; | ||
this.parameters = extractParameters(givenParameterTypes, resultMetadata); | ||
} | ||
|
||
static int[] extractParameters(int[] givenParameterTypes, ResultSet resultSet) { | ||
if (!resultSet.getMetadata().hasUndeclaredParameters()) { | ||
return givenParameterTypes; | ||
} | ||
return extractParameterTypes( | ||
givenParameterTypes, resultSet.getMetadata().getUndeclaredParameters()); | ||
} | ||
|
||
static int[] extractParameterTypes(int[] givenParameterTypes, StructType parameters) { | ||
int[] result; | ||
int maxParamIndex = maxParamNumber(parameters); | ||
if (maxParamIndex == givenParameterTypes.length) { | ||
result = givenParameterTypes; | ||
} else { | ||
result = | ||
Arrays.copyOf(givenParameterTypes, Math.max(givenParameterTypes.length, maxParamIndex)); | ||
} | ||
for (int i = 0; i < parameters.getFieldsCount(); i++) { | ||
// Only override parameter types that were not specified by the frontend. | ||
int paramIndex = Integer.parseInt(parameters.getFields(i).getName().substring(1)) - 1; | ||
if (paramIndex >= givenParameterTypes.length || givenParameterTypes[paramIndex] == 0) { | ||
result[paramIndex] = Parser.toOid(parameters.getFields(i).getType()); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
static int maxParamNumber(StructType parameters) { | ||
int max = 0; | ||
for (int i = 0; i < parameters.getFieldsCount(); i++) { | ||
try { | ||
int paramIndex = Integer.parseInt(parameters.getFields(i).getName().substring(1)); | ||
if (paramIndex > max) { | ||
max = paramIndex; | ||
} | ||
} catch (NumberFormatException numberFormatException) { | ||
throw PGExceptionFactory.newPGException( | ||
"Invalid parameter name: " + parameters.getFields(i).getName(), SQLState.InternalError); | ||
} | ||
} | ||
return max; | ||
} | ||
|
||
public int[] getParameters() { | ||
return parameters; | ||
} | ||
|
||
public ResultSet getResultSet() { | ||
return resultSet; | ||
} | ||
} |
44 changes: 0 additions & 44 deletions
44
src/main/java/com/google/cloud/spanner/pgadapter/metadata/DescribeStatementMetadata.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this required? What are the extra fields that are coming?
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.
The parameters are all named
p1
,p2
, ...p10
, ...So we need to parse the parameter index from the name by skipping the
p
, and we cannot use the position in the list as the index, as the order is textual, meaning that they are actually returned as (p1
,p10
,p2
, ...)