-
Notifications
You must be signed in to change notification settings - Fork 11
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
Fix connection pass through preventing functions from working #112
Merged
+255
−32
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
51 changes: 51 additions & 0 deletions
51
...ator-jdbc/src/main/java/com/linkedin/hoptimator/jdbc/schema/HoptimatorViewTableMacro.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,51 @@ | ||
package com.linkedin.hoptimator.jdbc.schema; | ||
|
||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import org.apache.calcite.jdbc.CalciteConnection; | ||
import org.apache.calcite.jdbc.CalcitePrepare; | ||
import org.apache.calcite.jdbc.CalciteSchema; | ||
import org.apache.calcite.schema.Schemas; | ||
import org.apache.calcite.schema.TranslatableTable; | ||
import org.apache.calcite.schema.impl.ViewTableMacro; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
* This file is copy-pasted from {@link ViewTableMacro} with the only modification being | ||
* how the connection is instantiated. | ||
*/ | ||
public class HoptimatorViewTableMacro extends ViewTableMacro { | ||
|
||
private final Boolean modifiable; | ||
public HoptimatorViewTableMacro(CalciteSchema schema, String viewSql, | ||
@Nullable List<String> schemaPath, @Nullable List<String> viewPath, | ||
@Nullable Boolean modifiable) { | ||
super(schema, viewSql, schemaPath, viewPath, modifiable); | ||
this.modifiable = modifiable; | ||
} | ||
|
||
public TranslatableTable apply(Properties properties) { | ||
CalciteConnection connection; | ||
try { | ||
connection = DriverManager.getConnection("jdbc:calcite:", properties) | ||
.unwrap(CalciteConnection.class); | ||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
CalcitePrepare.AnalyzeViewResult parsed = | ||
Schemas.analyzeView(connection, schema, schemaPath, viewSql, viewPath, | ||
modifiable != null && modifiable); | ||
final List<String> schemaPath1 = | ||
schemaPath != null ? schemaPath : schema.path(null); | ||
if ((modifiable == null || modifiable) | ||
&& parsed.modifiable | ||
&& parsed.table != null) { | ||
return modifiableViewTable(parsed, viewSql, schemaPath1, viewPath, schema); | ||
} else { | ||
return viewTable(parsed, viewSql, schemaPath1, viewPath); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
!set outputformat mysql | ||
!use k8s | ||
|
||
create or replace view ADS."case" AS SELECT CASE WHEN "FIRST_NAME" = 'Bob' THEN ARRAY['a'] ELSE ARRAY['b'] END || CASE WHEN "FIRST_NAME" = 'Alice' THEN ARRAY['c'] ELSE ARRAY['d'] END AS arr from profile.members; | ||
(0 rows modified) | ||
|
||
!update | ||
|
||
select * from ADS."case"; | ||
+--------+ | ||
| ARR | | ||
+--------+ | ||
| [b, c] | | ||
| [a, d] | | ||
| [b, d] | | ||
+--------+ | ||
(3 rows) | ||
|
||
!ok | ||
|
||
create or replace view ADS."json" AS SELECT JSON_VALUE('{"a": 1}', '$.a') AS json from profile.members; | ||
(0 rows modified) | ||
|
||
!update | ||
|
||
select * from ADS."json"; | ||
+------+ | ||
| JSON | | ||
+------+ | ||
| 1 | | ||
| 1 | | ||
| 1 | | ||
+------+ | ||
(3 rows) | ||
|
||
!ok | ||
|
||
create or replace view ADS."regex" AS SELECT REGEXP_REPLACE("FIRST_NAME", '(B)ob', '$1ill') AS name from profile.members; | ||
(0 rows modified) | ||
|
||
!update | ||
|
||
select * from ads."regex"; | ||
+---------+ | ||
| NAME | | ||
+---------+ | ||
| Alice | | ||
| Bill | | ||
| Charlie | | ||
+---------+ | ||
(3 rows) | ||
|
||
!ok | ||
|
||
create or replace view ADS."concat" AS SELECT CONCAT('_', "FIRST_NAME", '_') AS name from profile.members; | ||
(0 rows modified) | ||
|
||
!update | ||
|
||
select * from ads."concat"; | ||
+-----------+ | ||
| NAME | | ||
+-----------+ | ||
| _Alice_ | | ||
| _Bob_ | | ||
| _Charlie_ | | ||
+-----------+ | ||
(3 rows) | ||
|
||
!ok | ||
|
||
|
||
create or replace view ADS."listagg" AS SELECT LISTAGG("FIRST_NAME") AS agg FROM profile.members; | ||
(0 rows modified) | ||
|
||
!update | ||
|
||
select * from ads."listagg"; | ||
+-------------------+ | ||
| AGG | | ||
+-------------------+ | ||
| Alice,Bob,Charlie | | ||
+-------------------+ | ||
(1 row) | ||
|
||
!ok | ||
|
||
create or replace view ADS."unnested" AS SELECT * FROM UNNEST(ARRAY(SELECT "FIRST_NAME" FROM profile.members)) AS name; | ||
(0 rows modified) | ||
|
||
!update | ||
|
||
select * from ADS."unnested"; | ||
+---------+ | ||
| NAME | | ||
+---------+ | ||
| Alice | | ||
| Bob | | ||
| Charlie | | ||
+---------+ | ||
(3 rows) | ||
|
||
!ok | ||
|
||
drop view ads."case"; | ||
(0 rows modified) | ||
|
||
!update | ||
|
||
drop view ads."json"; | ||
(0 rows modified) | ||
|
||
!update | ||
|
||
drop view ads."regex"; | ||
(0 rows modified) | ||
|
||
!update | ||
|
||
drop view ads."concat"; | ||
(0 rows modified) | ||
|
||
!update | ||
|
||
drop view ads."listagg"; | ||
(0 rows modified) | ||
|
||
!update | ||
|
||
drop view ads."unnested"; | ||
(0 rows modified) | ||
|
||
!update |
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
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.
The
k1=v1;k2=v2
format seems to be a common convention, but not all drivers support it. We may run into drivers that choke on it. Not sure what to do in that case...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.
All the drivers we have for now do support it, so maybe that's good enough for now? Considering Properties objects are always key/value pairs I'd imagine we'd run into more problems if we just had single values