-
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
19
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 15 commits
Commits
Show all changes
19 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 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
10 changes: 10 additions & 0 deletions
10
...-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,10 @@ | ||
| 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); | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
| 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; | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
...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,19 @@ | ||
| 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); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
...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,10 @@ | ||
| 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); | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
...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,71 @@ | ||
| package com.google.cloud.spark.spanner.binding; | ||
|
|
||
| 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 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 { | ||
| 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 { | ||
|
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
28 changes: 28 additions & 0 deletions
28
...r-lib/src/main/java/com/google/cloud/spark/spanner/planning/query/ExprConverterUtils.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,28 @@ | ||
| package com.google.cloud.spark.spanner.planning.query; | ||
|
|
||
| import com.google.cloud.spark.spanner.planning.expression.*; | ||
| import org.apache.spark.sql.sources.*; | ||
| import org.apache.spark.sql.types.StructField; | ||
| import org.apache.spark.sql.types.StructType; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class ExprConverterUtils { | ||
| private static final Logger logger = LoggerFactory.getLogger(ExprConverterUtils.class); | ||
|
|
||
| public static ColumnExpr toColumn(String name, StructType schema) { | ||
| logger.debug("Looking up column '{}' in schema {}", name, schema.treeString()); | ||
|
|
||
| StructField field = schema.apply(name); | ||
|
|
||
| return new ColumnExpr(name, field.dataType(), field.nullable()); | ||
| } | ||
|
|
||
| public static LiteralExpr toLiteral(Object value, StructType schema, String columnName) { | ||
| logger.debug("Looking up literal column '{}' in schema {}", columnName, schema.treeString()); | ||
|
|
||
| StructField field = schema.apply(columnName); | ||
|
|
||
| return new LiteralExpr(value, field.dataType()); | ||
| } | ||
| } |
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
40 changes: 40 additions & 0 deletions
40
...rc/main/java/com/google/cloud/spark/spanner/rendering/GoogleSqlSpannerSqlExprVisitor.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,40 @@ | ||
| package com.google.cloud.spark.spanner.rendering; | ||
|
|
||
| import com.google.cloud.spanner.Dialect; | ||
| import com.google.cloud.spark.spanner.SpannerInformationSchema; | ||
| import com.google.cloud.spark.spanner.binding.ParameterRef; | ||
| import com.google.cloud.spark.spanner.binding.ParameterRegistry; | ||
| import com.google.cloud.spark.spanner.planning.expression.LiteralExpr; | ||
| import java.util.Collections; | ||
|
|
||
| public class GoogleSqlSpannerSqlExprVisitor extends SqlExprVisitor { | ||
|
|
||
| public GoogleSqlSpannerSqlExprVisitor() { | ||
| super( | ||
| SpannerInformationSchema.create(Dialect.GOOGLE_STANDARD_SQL), | ||
| ParameterRegistry.create(Dialect.GOOGLE_STANDARD_SQL)); | ||
| } | ||
|
|
||
| @Override | ||
| public RenderResult visit(LiteralExpr expr) { | ||
| ParameterRef ref = parameterRegistry.nextParameter(); | ||
|
|
||
| return new RenderResult( | ||
| "@" + ref.getSqlName(), Collections.singletonMap(ref.getBindName(), expr)); | ||
| } | ||
|
|
||
| @Override | ||
| public String renderStartsWith(String left, String right) { | ||
| return "STARTS_WITH(" + left + ", " + right + ")"; | ||
| } | ||
|
|
||
| @Override | ||
| public String renderEndsWith(String left, String right) { | ||
| return "ENDS_WITH(" + left + ", " + right + ")"; | ||
| } | ||
|
|
||
| @Override | ||
| public String renderContains(String left, String right) { | ||
| return "CONTAINS(" + left + ", " + right + ")"; | ||
| } | ||
| } |
Oops, something went wrong.
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.