-
Notifications
You must be signed in to change notification settings - Fork 23
Pushdown/join #210
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
Open
stevelordbq
wants to merge
20
commits into
GoogleCloudDataproc:main
Choose a base branch
from
Bit-Quill:pushdown/join
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pushdown/join #210
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d4130a2
Pushdown joins - initial AST
stevelordbq 9934567
Pushdown joins - Add predicate converter
stevelordbq 2cb081e
Pushdown joins - Add predicate converter unit test
stevelordbq d6b1ba3
Pushdown joins - PR updates
stevelordbq 5439080
Pushdown join - add SupportsPushDownJoin implementation
stevelordbq a3b39b5
Merge branch 'main' into pushdown/join
stevelordbq 4ade087
Pushdown Join: rebase with new AST
stevelordbq 698a65a
Pushdown Join: check for interleaving
stevelordbq c6b9870
Pushdown Join: Add join to LogicalQuery
stevelordbq 6191695
Pushdown Join: build JoinRelation
stevelordbq baadb8d
Pushdown Join: update AST validation
stevelordbq 0b9a824
Pushdown Join: add enablePredicateSql option to generate SQL from AST
stevelordbq 7373463
Pushdown Join: add parameter binding to AST SQL rendering
stevelordbq c9f064c
Merge branch 'main' into pushdown/join
stevelordbq 506e3e8
Pushdown Join: add switch to create Spark 41 SpannerTable for Spark 4…
stevelordbq 0564aae
Pushdown Join: cater for null values in interleave query.
stevelordbq 26a2b43
Pushdown Join: PR comments
stevelordbq 520d17a
Pushdown Join: Fix stack overflow
stevelordbq 34526f3
Pushdown Join: Add acceptance test
stevelordbq 92da451
Pushdown Join: spark.sql.optimizer.datasourceV2JoinPushdown required …
stevelordbq 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 hidden or 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 hidden or 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 hidden or 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
23 changes: 23 additions & 0 deletions
23
...-lib/src/main/java/com/google/cloud/spark/spanner/binding/GoogleSqlParameterRegistry.java
This file contains hidden or 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,23 @@ | ||
| // Copyright 2026 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.spark.spanner.binding; | ||
|
|
||
| public class GoogleSqlParameterRegistry extends ParameterRegistry { | ||
| @Override | ||
| public ParameterRef nextParameter() { | ||
| counter++; | ||
| final String name = "p" + String.valueOf(counter); | ||
| return new ParameterRef(name, name); | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
spark-3.1-spanner-lib/src/main/java/com/google/cloud/spark/spanner/binding/ParameterRef.java
This file contains hidden or 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,32 @@ | ||
| // Copyright 2026 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.spark.spanner.binding; | ||
|
|
||
| public class ParameterRef { | ||
| private final String bindName; | ||
| private final String sqlName; | ||
|
|
||
| public ParameterRef(String bindName, String sqlName) { | ||
| this.bindName = bindName; | ||
| this.sqlName = sqlName; | ||
| } | ||
|
|
||
| public String getBindName() { | ||
| return bindName; | ||
| } | ||
|
|
||
| public String getSqlName() { | ||
| return sqlName; | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...1-spanner-lib/src/main/java/com/google/cloud/spark/spanner/binding/ParameterRegistry.java
This file contains hidden or 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,32 @@ | ||
| // Copyright 2026 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.spark.spanner.binding; | ||
|
|
||
| import com.google.cloud.spanner.Dialect; | ||
|
|
||
| public abstract class ParameterRegistry { | ||
| protected int counter = 0; | ||
|
|
||
| public abstract ParameterRef nextParameter(); | ||
|
|
||
| public static ParameterRegistry create(Dialect dialect) { | ||
| switch (dialect) { | ||
| case POSTGRESQL: | ||
| return new PostgresSqlParameterRegistry(); | ||
| case GOOGLE_STANDARD_SQL: | ||
| return new GoogleSqlParameterRegistry(); | ||
| } | ||
| throw new IllegalArgumentException("Unsupported dialect: " + dialect); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...ib/src/main/java/com/google/cloud/spark/spanner/binding/PostgresSqlParameterRegistry.java
This file contains hidden or 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,23 @@ | ||
| // Copyright 2026 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.spark.spanner.binding; | ||
|
|
||
| public class PostgresSqlParameterRegistry extends ParameterRegistry { | ||
| @Override | ||
| public ParameterRef nextParameter() { | ||
| counter++; | ||
| final String name = String.valueOf(counter); | ||
| return new ParameterRef("p" + name, name); | ||
| } | ||
| } |
127 changes: 127 additions & 0 deletions
127
...1-spanner-lib/src/main/java/com/google/cloud/spark/spanner/binding/SpannerTypeBinder.java
This file contains hidden or 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,127 @@ | ||
| // Copyright 2026 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.spark.spanner.binding; | ||
|
|
||
| import com.google.cloud.ByteArray; | ||
| import com.google.cloud.spanner.Statement; | ||
| import com.google.cloud.spanner.Type; | ||
| import com.google.cloud.spark.spanner.planning.expression.LiteralExpr; | ||
| import java.math.BigDecimal; | ||
| import java.time.Instant; | ||
| import org.apache.spark.sql.types.DataType; | ||
| import org.apache.spark.sql.types.DataTypes; | ||
| import org.apache.spark.sql.types.DecimalType; | ||
|
|
||
| public final class SpannerTypeBinder { | ||
|
|
||
| public static void bind(Statement.Builder builder, String parameter, LiteralExpr literal) { | ||
|
|
||
| Object value = literal.getValue(); | ||
| DataType type = literal.getSparkType(); | ||
|
|
||
| if (value == null) { | ||
| builder.bind(parameter).to(mapToSpannerType(type), (com.google.cloud.spanner.Struct) null); | ||
| return; | ||
| } | ||
|
|
||
| if (type instanceof DecimalType) { | ||
|
stevelordbq marked this conversation as resolved.
|
||
| BigDecimal bd = (BigDecimal) value; | ||
| // Spanner NUMERIC validation: precision <= 38, scale <= 9 | ||
| if (bd.precision() <= 38 && bd.scale() <= 9) { | ||
| builder.bind(parameter).to(bd); | ||
| } else { | ||
| throw new IllegalArgumentException("Decimal out of Spanner NUMERIC range"); | ||
| } | ||
|
stevelordbq marked this conversation as resolved.
|
||
| } else if (type.sameType(DataTypes.StringType)) { | ||
| builder.bind(parameter).to((String) value); | ||
| } else if (type.sameType(DataTypes.LongType)) { | ||
| builder.bind(parameter).to((Long) value); | ||
| } else if (type.sameType(DataTypes.BooleanType)) { | ||
| builder.bind(parameter).to((Boolean) value); | ||
| } else if (type.sameType(DataTypes.IntegerType)) { | ||
| builder.bind(parameter).to(((Integer) value).longValue()); | ||
| } else if (type.sameType(DataTypes.ShortType)) { | ||
| builder.bind(parameter).to(((Short) value).longValue()); | ||
| } else if (type.sameType(DataTypes.ByteType)) { | ||
| builder.bind(parameter).to(((Byte) value).longValue()); | ||
| } else if (type.sameType(DataTypes.DoubleType)) { | ||
| builder.bind(parameter).to((Double) value); | ||
| } else if (type.sameType(DataTypes.FloatType)) { | ||
| builder.bind(parameter).to(((Float) value).doubleValue()); | ||
| } else if (type.sameType(DataTypes.TimestampType)) { | ||
|
|
||
| if (value instanceof Instant) { | ||
| Instant instant = (Instant) value; | ||
| builder | ||
| .bind(parameter) | ||
| .to( | ||
| com.google.cloud.Timestamp.ofTimeSecondsAndNanos( | ||
| instant.getEpochSecond(), instant.getNano())); | ||
|
|
||
| } else if (value instanceof java.sql.Timestamp) { | ||
| java.sql.Timestamp ts = (java.sql.Timestamp) value; | ||
| Instant instant = ts.toInstant(); | ||
| builder | ||
| .bind(parameter) | ||
| .to( | ||
| com.google.cloud.Timestamp.ofTimeSecondsAndNanos( | ||
| instant.getEpochSecond(), instant.getNano())); | ||
|
|
||
| } else { | ||
| throw new IllegalArgumentException( | ||
| "Unexpected timestamp literal type: " + value.getClass()); | ||
| } | ||
| } else if (type.sameType(DataTypes.DateType)) { | ||
| java.sql.Date date = (java.sql.Date) value; | ||
|
|
||
| builder | ||
| .bind(parameter) | ||
| .to( | ||
| com.google.cloud.Date.fromYearMonthDay( | ||
| date.toLocalDate().getYear(), | ||
| date.toLocalDate().getMonthValue(), | ||
| date.toLocalDate().getDayOfMonth())); | ||
| } else if (type.sameType(DataTypes.BinaryType)) { | ||
| builder.bind(parameter).to(ByteArray.copyFrom((byte[]) value)); | ||
| } else { | ||
| throw new UnsupportedOperationException("Unsupported type: " + type); | ||
| } | ||
| } | ||
|
|
||
| private static Type mapToSpannerType(DataType type) { | ||
| if (type instanceof DecimalType) { | ||
| return Type.numeric(); | ||
| } else if (type.sameType(DataTypes.StringType)) { | ||
| return Type.string(); | ||
| } else if (type.sameType(DataTypes.LongType) | ||
| || type.sameType(DataTypes.IntegerType) | ||
| || type.sameType(DataTypes.ShortType) | ||
| || type.sameType(DataTypes.ByteType)) { | ||
| return Type.int64(); | ||
| } else if (type.sameType(DataTypes.BooleanType)) { | ||
| return Type.bool(); | ||
| } else if (type.sameType(DataTypes.DoubleType) || type.sameType(DataTypes.FloatType)) { | ||
| return Type.float64(); | ||
| } else if (type.sameType(DataTypes.TimestampType)) { | ||
| return Type.timestamp(); | ||
| } else if (type.sameType(DataTypes.DateType)) { | ||
| return Type.date(); | ||
| } else if (type.sameType(DataTypes.BinaryType)) { | ||
| return Type.bytes(); | ||
| } else { | ||
|
stevelordbq marked this conversation as resolved.
|
||
| throw new UnsupportedOperationException( | ||
| "Unsupported Spark type for Spanner null mapping: " + type); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.