-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix connection pass through preventing functions from working (#112)
* Fix connection pass through preventing functions from working * Add comment
- Loading branch information
Showing
13 changed files
with
255 additions
and
32 deletions.
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
Oops, something went wrong.