Skip to content

Commit

Permalink
Fixed date handling for calcite graphql adapter.
Browse files Browse the repository at this point in the history
Added a sqlengine - for http sql api.
Made query parsing identifiers case-sensitive to match PostgresSQL style.
  • Loading branch information
kenstott committed Nov 5, 2024
1 parent a8e7c2e commit 05e563d
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 52 deletions.
256 changes: 205 additions & 51 deletions calcite-rs-jni/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,104 +8,243 @@
<artifactId>ndc-calcite</artifactId>
<version>1.0.0</version>
</parent>

<artifactId>graphql-jdbc-driver</artifactId>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<calcite.version>1.38.0-SNAPSHOT</calcite.version>
<jar.version>1.0.0</jar.version>

<!-- Dependency versions -->
<kotlin.version>1.9.10</kotlin.version>
<jackson.version>2.15.2</jackson.version>
<slf4j.version>1.7.36</slf4j.version>
<commons-lang3.version>3.11</commons-lang3.version>
<reactive-streams.version>1.0.3</reactive-streams.version>
<httpcore5.version>5.2.3</httpcore5.version>
<avatica.version>1.25.0</avatica.version>
<graphql-java.version>22.3</graphql-java.version>
<graphql-java-tools.version>11.0.1</graphql-java-tools.version>
<okhttp.version>4.12.0</okhttp.version>
<commons-codec.version>1.15</commons-codec.version>
<commons-math.version>3.6.1</commons-math.version>
<commons-text.version>1.9</commons-text.version>
<guava.version>33.0.0-jre</guava.version>
<janino.version>3.1.6</janino.version>
<json-path.version>2.3.0</json-path.version>
<jts.version>1.18.1</jts.version>
<log4j.version>2.14.1</log4j.version>
</properties>

<dependencyManagement>
<dependencies>
<!-- Kotlin -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-common</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk7</artifactId>
<version>${kotlin.version}</version>
</dependency>

<!-- Jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>

<!-- SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- Apache Commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>

<!-- Reactive Streams -->
<dependency>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
<version>${reactive-streams.version}</version>
</dependency>

<!-- HTTP Components -->
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<version>${httpcore5.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Calcite -->
<dependency>
<groupId>org.apache.calcite.avatica</groupId>
<artifactId>avatica-core</artifactId>
<version>1.25.0</version>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<version>${calcite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-graphql</artifactId>
<version>${calcite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-linq4j</artifactId>
<version>${calcite.version}</version>
</dependency>

<!-- GraphQL -->
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
<version>22.3</version>
<version>${graphql-java.version}</version>
<exclusions>
<exclusion>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>11.0.1</version>
<version>${graphql-java-tools.version}</version>
<exclusions>
<exclusion>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
</exclusion>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- HTTP Client -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.0.0-jre</version>
<version>${okhttp.version}</version>
</dependency>

<!-- Avatica -->
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.18.1</version>
<groupId>org.apache.calcite.avatica</groupId>
<artifactId>avatica-core</artifactId>
<version>${avatica.version}</version>
</dependency>

<!-- Runtime Dependencies -->
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.1.6</version>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
<version>${commons-math.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
<version>${commons-text.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<version>${calcite.version}</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-graphql</artifactId>
<version>${calcite.version}</version>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>${janino.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-linq4j</artifactId>
<version>${calcite.version}</version>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${json-path.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>${jts.version}</version>
<scope>runtime</scope>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
Expand All @@ -114,6 +253,29 @@
</resource>
</resources>
<plugins>
<!-- Enforcer Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireUpperBoundDeps />
<dependencyConvergence />
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>

<!-- Exec Plugin for Installing Local Dependencies -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
Expand Down Expand Up @@ -175,19 +337,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<compress>false</compress>
</archive>
</configuration>
</plugin>

<!-- Assembly Plugin for Fat JAR -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<version>3.7.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public Connection connect(String url, Properties info) throws SQLException {

Properties calciteProps = new Properties();
calciteProps.setProperty("fun", "standard");
calciteProps.setProperty("caseSensitive", "true");
calciteProps.setProperty("unquotedCasing", "UNCHANGED");
calciteProps.setProperty("quotedCasing", "UNCHANGED");

Connection connection = DriverManager.getConnection("jdbc:calcite:", calciteProps);
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.calcite.adapter.enumerable.EnumerableConvention;
import org.apache.calcite.adapter.enumerable.EnumerableRules;
import org.apache.calcite.adapter.graphql.GraphQLRules;
import org.apache.calcite.avatica.util.Casing;
import org.apache.calcite.jdbc.CalciteConnection;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelOptRule;
Expand All @@ -16,6 +17,7 @@
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.validate.SqlConformanceEnum;
import org.apache.calcite.tools.*;

import java.sql.Connection;
Expand All @@ -38,6 +40,9 @@ public class CalciteModelPlanner {
public static void displayQueryPlan(String modelPath, String sql) throws Exception {
Properties info = new Properties();
info.put("model", modelPath);
info.setProperty("caseSensitive", "true");
info.setProperty("unquotedCasing", "UNCHANGED");
info.setProperty("quotedCasing", "UNCHANGED");

Connection connection = DriverManager.getConnection("jdbc:calcite:", info);
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
Expand Down Expand Up @@ -72,10 +77,17 @@ public static void displayQueryPlan(String modelPath, String sql) throws Excepti
hepProgramBuilder.addMatchOrder(HepMatchOrder.TOP_DOWN);
rules.forEach(hepProgramBuilder::addRuleInstance);

// Set the SQL parser configuration
SqlParser.Config parserConfig = SqlParser.config()
.withCaseSensitive(true) // For distinguishing between "name" and "Name"
.withUnquotedCasing(Casing.UNCHANGED) // Keep original case for unquoted identifiers
.withQuotedCasing(Casing.UNCHANGED) // Keep original case for quoted identifiers
.withConformance(SqlConformanceEnum.LENIENT);

// Create planner configuration
FrameworkConfig config = Frameworks.newConfigBuilder()
.defaultSchema(rootSchema)
.parserConfig(SqlParser.Config.DEFAULT)
.parserConfig(parserConfig)
.programs(Programs.sequence(
Programs.ofRules(rules),
Programs.ofRules(GraphQLRules.PROJECT_RULE),
Expand Down
Loading

0 comments on commit 05e563d

Please sign in to comment.