diff --git a/.github/workflows/buildcache.yml b/.github/workflows/buildcache.yml index 10c921f0cb2..42eb1767ed3 100644 --- a/.github/workflows/buildcache.yml +++ b/.github/workflows/buildcache.yml @@ -25,13 +25,14 @@ jobs: name: '${{ matrix.os }}, ${{ matrix.jdk }} seed build cache' runs-on: ${{ matrix.os }}-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 50 - name: 'Set up JDK ${{ matrix.jdk }}' uses: actions/setup-java@v1 with: java-version: ${{ matrix.jdk }} + distribution: 'zulu' - uses: burrunan/gradle-cache-action@v1 name: Build Calcite env: diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 405a2b30659..8bfd0dcf51f 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -6,5 +6,5 @@ jobs: name: "Validation" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: gradle/wrapper-validation-action@v1 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ac12876aa85..fd397a24052 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,18 +47,19 @@ env: _JAVA_OPTIONS: '-XX:GCTimeLimit=90 -XX:GCHeapFreeLimit=35' jobs: - windows: + windows-jdk8: if: github.event.action != 'labeled' name: 'Windows (JDK 8)' runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 50 - name: 'Set up JDK 8' - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: java-version: 8 + distribution: 'zulu' - uses: burrunan/gradle-cache-action@v1 name: Test env: @@ -79,15 +80,150 @@ jobs: echo sqlsh call sqlsh.bat -o headers "select count(*) commits, author from (select substring(author, 1, position(' <' in author)-1) author from git_commits) group by author order by count(*) desc, author limit 20" + windows-jdk17: + if: github.event.action != 'labeled' + name: 'Windows (JDK 17)' + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 50 + - name: 'Set up JDK 17' + uses: actions/setup-java@v2 + with: + java-version: 17 + distribution: 'zulu' + - uses: burrunan/gradle-cache-action@v1 + name: Test + env: + S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }} + S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }} + with: + job-id: jdk${{ matrix.jdk }} + remote-build-cache-proxy-enabled: false + arguments: --scan --no-parallel --no-daemon build + - name: 'sqlline and sqllsh' + shell: cmd + run: | + call sqlline.bat -e '!quit' + echo. + echo Sqlline example/csv + call example/csv/sqlline.bat --verbose -u jdbc:calcite:model=example/csv/src/test/resources/model.json -n admin -p admin -f example/csv/src/test/resources/smoke_test.sql + echo. + echo sqlsh + call sqlsh.bat -o headers "select count(*) commits, author from (select substring(author, 1, position(' <' in author)-1) author from git_commits) group by author order by count(*) desc, author limit 20" + + linux-jdk8-oldest-guava-tz: + if: github.event.action != 'labeled' + name: 'Linux (JDK 8), Oldest Guava, America/New_York Timezone' + runs-on: ubuntu-latest + env: + TZ: 'America/New_York' # flips between −05:00 and −04:00 + GUAVA: '16.0.1' # oldest supported Guava version + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 50 + - name: 'Set up JDK 8' + uses: actions/setup-java@v2 + with: + java-version: 8 + distribution: 'zulu' + - uses: burrunan/gradle-cache-action@v1 + name: Test + env: + S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }} + S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }} + with: + job-id: jdk${{ matrix.jdk }} + remote-build-cache-proxy-enabled: false + arguments: --scan --no-parallel --no-daemon -Pguava.version=${{ env.GUAVA }} build + + linux-jdk11-tz: + if: github.event.action != 'labeled' + name: 'Linux (JDK 11), Pacific/Chatham Timezone' + runs-on: ubuntu-latest + env: + TZ: 'Pacific/Chatham' # flips between +12:45 and +13:45 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 50 + - name: 'Set up JDK 11' + uses: actions/setup-java@v2 + with: + java-version: 11 + distribution: 'zulu' + - uses: burrunan/gradle-cache-action@v1 + name: Test + env: + S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }} + S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }} + with: + job-id: jdk${{ matrix.jdk }} + remote-build-cache-proxy-enabled: false + arguments: --scan --no-parallel --no-daemon build + + linux-jdk17: # LTS JDK version, don't remove until EOL + if: github.event.action != 'labeled' + name: 'Linux (JDK 17)' + runs-on: ubuntu-latest + env: + GUAVA: '31.1-jre' + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 50 + - name: 'Set up JDK 17' + uses: actions/setup-java@v2 + with: + java-version: 17 + distribution: 'zulu' + - uses: burrunan/gradle-cache-action@v1 + name: Test + env: + S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }} + S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }} + with: + job-id: jdk${{ matrix.jdk }} + remote-build-cache-proxy-enabled: false + arguments: --scan --no-parallel --no-daemon -Pguava.version=${{ env.GUAVA }} build + + linux-jdk18: # latest JDK version supported by ForbiddenAPIs plugin, keep this updated (see https://jdk.java.net/) + if: github.event.action != 'labeled' + name: 'Linux (JDK 18)' + runs-on: ubuntu-latest + env: + GUAVA: '31.1-jre' + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 50 + - name: 'Set up JDK 18' + uses: actions/setup-java@v2 + with: + java-version: 18 + distribution: 'zulu' + - uses: burrunan/gradle-cache-action@v1 + name: Test + env: + S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }} + S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }} + with: + job-id: jdk${{ matrix.jdk }} + remote-build-cache-proxy-enabled: false + arguments: --scan --no-parallel --no-daemon -Pguava.version=${{ env.GUAVA }} build + linux-avatica: if: github.event.action != 'labeled' name: 'Linux (JDK 11), Avatica main' runs-on: ubuntu-latest steps: - name: 'Set up JDK 11' - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: java-version: 11 + distribution: 'zulu' - name: 'Clone Avatica to Maven Local repository' run: | git clone --branch main --depth 100 https://github.com/apache/calcite-avatica.git ../calcite-avatica @@ -104,7 +240,7 @@ jobs: properties: | calcite.avatica.version=1.0.0-dev-main skipJavadoc= - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 50 - uses: burrunan/gradle-cache-action@v1 @@ -121,29 +257,28 @@ jobs: calcite.avatica.version=1.0.0-dev-main-SNAPSHOT enableMavenLocal= - linux-openj9: + mac: if: github.event.action != 'labeled' - name: 'Linux (OpenJ9 8)' + name: 'macOS (JDK 18)' runs-on: macos-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 50 - - uses: AdoptOpenJDK/install-jdk@v1 + - name: 'Set up JDK 18' + uses: actions/setup-java@v2 with: - impl: openj9 - version: '8' - architecture: x64 + java-version: 18 + distribution: 'zulu' - uses: burrunan/gradle-cache-action@v1 name: Test env: S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }} S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }} with: - job-id: jdk8-openj9 + job-id: jdk18 remote-build-cache-proxy-enabled: false - # Temporarily disable hadoop related tests due to https://github.com/eclipse-openj9/openj9/issues/14950 - arguments: --scan --no-parallel --no-daemon -x :piglet:test -x :spark:test build javadoc + arguments: --scan --no-parallel --no-daemon build javadoc - name: 'sqlline and sqllsh' run: | ./sqlline -e '!quit' @@ -154,49 +289,44 @@ jobs: echo sqlsh ./sqlsh -o headers "select count(*) commits, author from (select substring(author, 1, position(' <' in author)-1) author from git_commits) group by author order by count(*) desc, author limit 20" - mac: + errorprone: if: github.event.action != 'labeled' - name: 'macOS (JDK 18)' - runs-on: macos-latest + name: 'Error Prone (JDK 11)' + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 50 - - name: 'Set up JDK 18' - uses: actions/setup-java@v1 + - name: 'Set up JDK 11' + uses: actions/setup-java@v2 with: - java-version: 18 + java-version: 11 + distribution: 'zulu' - uses: burrunan/gradle-cache-action@v1 name: Test env: S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }} S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }} with: - job-id: jdk18 + job-id: errprone remote-build-cache-proxy-enabled: false - arguments: --scan --no-parallel --no-daemon build javadoc - - name: 'sqlline and sqllsh' - run: | - ./sqlline -e '!quit' - echo - echo Sqlline example/csv - ./example/csv/sqlline --verbose -u jdbc:calcite:model=example/csv/src/test/resources/model.json -n admin -p admin -f example/csv/src/test/resources/smoke_test.sql - echo - echo sqlsh - ./sqlsh -o headers "select count(*) commits, author from (select substring(author, 1, position(' <' in author)-1) author from git_commits) group by author order by count(*) desc, author limit 20" + arguments: --scan --no-parallel --no-daemon -PenableErrorprone classes - errorprone: + errorprone-guava31: # LTS JDK version, don't remove until EOL if: github.event.action != 'labeled' - name: 'Error Prone (JDK 11)' + name: 'Error Prone (JDK 11), Guava 31' runs-on: ubuntu-latest + env: + GUAVA: '31.1-jre' # ErrorProne checks for Beta APIs, so use the newest supported Guava version steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 50 - name: 'Set up JDK 11' - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: java-version: 11 + distribution: 'zulu' - uses: burrunan/gradle-cache-action@v1 name: Test env: @@ -205,19 +335,20 @@ jobs: with: job-id: errprone remote-build-cache-proxy-enabled: false - arguments: --scan --no-parallel --no-daemon -PenableErrorprone classes + arguments: --scan --no-parallel --no-daemon -Pguava.version=${{ env.GUAVA }} -PenableErrorprone classes linux-checkerframework: name: 'CheckerFramework (JDK 11)' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 50 - name: 'Set up JDK 11' - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: java-version: 11 + distribution: 'zulu' - name: 'Run CheckerFramework' uses: burrunan/gradle-cache-action@v1 env: @@ -228,6 +359,30 @@ jobs: remote-build-cache-proxy-enabled: false arguments: --scan --no-parallel --no-daemon -PenableCheckerframework :linq4j:classes :core:classes + linux-checkerframework-guava29: + name: 'CheckerFramework (JDK 11), Guava 29' + runs-on: ubuntu-latest + env: + GUAVA: '29.0-jre' + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 50 + - name: 'Set up JDK 11' + uses: actions/setup-java@v2 + with: + java-version: 11 + distribution: 'zulu' + - name: 'Run CheckerFramework' + uses: burrunan/gradle-cache-action@v1 + env: + S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }} + S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }} + with: + job-id: checkerframework-jdk11 + remote-build-cache-proxy-enabled: false + arguments: --scan --no-parallel --no-daemon -Pguava.version=${{ env.GUAVA }} -PenableCheckerframework :linq4j:classes :core:classes + linux-slow: # Run slow tests when the commit is on main or it is requested explicitly by adding an # appropriate label in the PR @@ -235,13 +390,14 @@ jobs: name: 'Linux (JDK 8) Slow Tests' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 50 - name: 'Set up JDK 8' - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: java-version: 8 + distribution: 'zulu' - uses: burrunan/gradle-cache-action@v1 name: Test env: @@ -254,13 +410,14 @@ jobs: linux-druid: if: github.event.action != 'labeled' - name: 'Linux (JDK 8) Druid Tests' + name: 'Druid Tests' runs-on: ubuntu-latest steps: - - name: 'Set up JDK 8' - uses: actions/setup-java@v1 + - name: 'Set up JDK 17' + uses: actions/setup-java@v2 with: - java-version: 8 + java-version: 17 + distribution: 'zulu' - name: 'Checkout Druid dataset' uses: actions/checkout@v3 with: @@ -282,7 +439,7 @@ jobs: - name: 'Index Foodmart/Wikipedia datasets' working-directory: ./druid-dataset run: ./index.sh 30s - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 1 path: calcite diff --git a/.gitignore b/.gitignore index 0602bdcdd14..9425771f747 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,12 @@ /buildSrc/subprojects/*/build /site/.jekyll-cache +# VSCode Java plugin +/example/*/bin +/*/bin +/bin +/.vscode/* + # IDEA /out /*/out/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 36cea90b63c..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,77 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to you 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. -# - -# Configuration file for Travis continuous integration. -# See https://travis-ci.com/github/apache/calcite -language: java -matrix: - fast_finish: true - include: - - jdk: openjdk8 - env: - - TZ=America/New_York # flips between −05:00 and −04:00 - - GUAVA=19.0 # oldest supported Guava version - - jdk: openjdk11 - env: - - CHECKERFRAMEWORK=Y - script: - - export _JAVA_OPTIONS="-XX:GCTimeLimit=90 -XX:GCHeapFreeLimit=35" - - travis_wait ./gradlew --no-parallel --no-daemon --scan -Pguava.version=${GUAVA:-29.0-jre} -PenableCheckerframework :linq4j:classes :core:classes - - jdk: openjdk11 - env: - - ERRORPRONE=Y - - GUAVA=31.1-jre # ErrorProne checks for Beta APIs, so use newest supported Guava version - script: - - export _JAVA_OPTIONS="-XX:GCTimeLimit=90 -XX:GCHeapFreeLimit=35" - - ./gradlew --no-parallel --no-daemon --scan -Pguava.version=${GUAVA:-29.0-jre} -PenableErrorprone classes - - jdk: openjdk11 - env: - - TZ=Pacific/Chatham # flips between +12:45 and +13:45 - - jdk: openjdk15 - env: - - GUAVA=31.1-jre # newest supported Guava version - - jdk: openjdk16 - env: - - GUAVA=31.1-jre - - jdk: openjdk17 - env: - - GUAVA=31.1-jre - - jdk: openjdk18 - env: - - GUAVA=31.1-jre -branches: - only: - - main - - javadoc - - /^branch-.*$/ - - /^[0-9]+-.*$/ -install: true -script: - # Throw OutOfMemoryError in case less than 35% is free after full GC - # This avoids never-ending GC trashing if memory gets too low in case of a memory leak - - export _JAVA_OPTIONS="-XX:GCTimeLimit=90 -XX:GCHeapFreeLimit=35" - - ./gradlew --no-daemon -Pguava.version=${GUAVA:-29.0-jre} build -git: - depth: 100 -cache: - directories: - - $HOME/.gradle/caches/ - - $HOME/.gradle/wrapper/ - -before_cache: - - ./gradlew --stop - - F=CleanupGradleCache sh -x -c 'curl -O https://raw.githubusercontent.com/vlsi/cleanup-gradle-cache/v1.x/$F.java && javac -J-Xmx128m $F.java && java -Xmx128m $F' diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000000..53cc1e6f31f --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you 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. + */ + +node('ubuntu') { + def JAVA_JDK_17=tool name: 'jdk_17_latest', type: 'hudson.model.JDK' + stage('Checkout') { + if(env.CHANGE_ID) { + // By default checkout on PRs will fetch only that branch and nothing else. However, in order for the Sonar plugin + // to function properly we need to fetch also the target branch ${CHANGE_TARGET} so we need to customize the + // refspec. If the target branch of the PR is not present warnings like the following may appear: + // Could not find ref 'main' in refs/heads, refs/remotes/upstream or refs/remotes/origin + checkout([ + $class: 'GitSCM', + branches: scm.branches, + doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations, + extensions: scm.extensions, + userRemoteConfigs: scm.userRemoteConfigs + [[ + name: 'origin', + refspec: scm.userRemoteConfigs[0].refspec+ " +refs/heads/${CHANGE_TARGET}:refs/remotes/origin/${CHANGE_TARGET}", + url: scm.userRemoteConfigs[0].url, + credentialsId: scm.userRemoteConfigs[0].credentialsId + ]], + ]) + } else { + checkout scm + } + } + stage('Code Quality') { + timeout(time: 1, unit: 'HOURS') { + withEnv(["Path+JDK=$JAVA_JDK_17/bin","JAVA_HOME=$JAVA_JDK_17"]) { + withCredentials([string(credentialsId: 'SONARCLOUD_TOKEN', variable: 'SONAR_TOKEN')]) { + if ( env.BRANCH_NAME.startsWith("PR-") ) { + sh './gradlew --no-parallel --no-daemon jacocoAggregateTestReport sonar -PenableJacoco -Dsonar.pullrequest.branch=${CHANGE_BRANCH} -Dsonar.pullrequest.base=${CHANGE_TARGET} -Dsonar.pullrequest.key=${CHANGE_ID} -Dsonar.login=${SONAR_TOKEN}' + } else { + sh './gradlew --no-parallel --no-daemon jacocoAggregateTestReport sonar -PenableJacoco -Dsonar.branch.name=${BRANCH_NAME} -Dsonar.login=${SONAR_TOKEN}' + } + } + } + } + } + cleanWs() +} + diff --git a/NOTICE b/NOTICE index fb342f9c909..f4562f0e62a 100644 --- a/NOTICE +++ b/NOTICE @@ -1,5 +1,5 @@ Apache Calcite -Copyright 2012-2022 The Apache Software Foundation +Copyright 2012-2023 The Apache Software Foundation This product includes software developed at The Apache Software Foundation (http://www.apache.org/). diff --git a/README b/README index 3365c5e341e..87c004816e5 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Apache Calcite release 1.30.0 +Apache Calcite release 1.34.0 This is a source or binary distribution of Apache Calcite. diff --git a/README.md b/README.md index d9277043703..af6a60e2dab 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,7 @@ limitations under the License. --> [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.calcite/calcite-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.calcite/calcite-core) -[![Travis Build Status](https://app.travis-ci.com/apache/calcite.svg?branch=main)](https://app.travis-ci.com/github/apache/calcite) [![CI Status](https://github.com/apache/calcite/workflows/CI/badge.svg?branch=main)](https://github.com/apache/calcite/actions?query=branch%3Amain) -[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/apache/calcite?svg=true&branch=main)](https://ci.appveyor.com/project/ApacheSoftwareFoundation/calcite) # Apache Calcite @@ -37,3 +35,6 @@ Elasticsearch, MongoDB, Kafka, and others, with minimal configuration. For more details, see the [home page](http://calcite.apache.org). + +The project uses [JIRA](https://issues.apache.org/jira/browse/CALCITE) +for issue tracking. For further information, please see the [JIRA accounts guide](https://calcite.apache.org/develop/#jira-accounts). diff --git a/babel/src/main/codegen/config.fmpp b/babel/src/main/codegen/config.fmpp index f75631e739a..a61dee55e29 100644 --- a/babel/src/main/codegen/config.fmpp +++ b/babel/src/main/codegen/config.fmpp @@ -30,14 +30,25 @@ data: { "org.apache.calcite.sql.SqlCreate", "org.apache.calcite.sql.babel.SqlBabelCreateTable", "org.apache.calcite.sql.babel.TableCollectionType", + "org.apache.calcite.sql.babel.postgresql.AndChain", + "org.apache.calcite.sql.babel.postgresql.SqlBegin", + "org.apache.calcite.sql.babel.postgresql.SqlCommit", + "org.apache.calcite.sql.babel.postgresql.SqlDiscard", + "org.apache.calcite.sql.babel.postgresql.SqlRollback", + "org.apache.calcite.sql.babel.postgresql.SqlShow", "org.apache.calcite.sql.ddl.SqlDdlNodes", ] # List of new keywords. Example: "DATABASES", "TABLES". If the keyword is # not a reserved keyword, add it to the 'nonReservedKeywords' section. keywords: [ + "DISCARD" "IF" + "PLANS" + "SEED" "SEMI" + "SEQUENCES" + "TEMP" "VOLATILE" ] @@ -45,7 +56,13 @@ data: { # items in this list become non-reserved nonReservedKeywordsToAdd: [ # not in core, added in babel + "DISCARD" + "IF" + "PLANS" + "SEED" "SEMI" + "SEQUENCES" + "TEMP" # The following keywords are reserved in core Calcite, # are reserved in some version of SQL, @@ -156,6 +173,7 @@ data: { "CYCLE" "DATA" # "DATE" + "DATETIME_DIFF" "DAY" "DEALLOCATE" "DEC" @@ -236,7 +254,6 @@ data: { "HOLD" "HOUR" "IDENTITY" -# "IF" # not a keyword in Calcite "ILIKE" "IMMEDIATE" "IMMEDIATELY" @@ -463,7 +480,11 @@ data: { "TEMPORARY" # "THEN" # "TIME" + "TIME_DIFF" + "TIME_TRUNC" # "TIMESTAMP" + "TIMESTAMP_DIFF" + "TIMESTAMP_TRUNC" "TIMEZONE_HOUR" "TIMEZONE_MINUTE" "TINYINT" @@ -528,9 +549,8 @@ data: { # List of methods for parsing builtin function calls. # Return type of method implementation should be "SqlNode". - # Example: "DateFunctionCall()". + # Example: "DateaddFunctionCall()". builtinFunctionCallMethods: [ - "DateFunctionCall()" "DateaddFunctionCall()" ] @@ -540,6 +560,15 @@ data: { createStatementParserMethods: [ "SqlCreateTable" ] + + statementParserMethods: [ + "PostgresqlSqlShow()", + "PostgresqlSqlSetOption()", + "PostgresqlSqlBegin()", + "PostgresqlSqlDiscard()", + "PostgresqlSqlCommit()", + "PostgresqlSqlRollback()" + ] # Binary operators tokens. # Example: "< INFIX_CAST: \"::\" >". @@ -562,9 +591,11 @@ data: { # Example: "parserImpls.ftl". implementationFiles: [ "parserImpls.ftl" + "parserPostgresqlImpls.ftl" ] includePosixOperators: true + includeParsingStringLiteralAsArrayLiteral: true } } diff --git a/babel/src/main/codegen/includes/parserImpls.ftl b/babel/src/main/codegen/includes/parserImpls.ftl index 2e9134750d6..fb169fe1e8e 100644 --- a/babel/src/main/codegen/includes/parserImpls.ftl +++ b/babel/src/main/codegen/includes/parserImpls.ftl @@ -22,42 +22,23 @@ JoinType LeftSemiJoin() : { return JoinType.LEFT_SEMI_JOIN; } } -SqlNode DateFunctionCall() : -{ - final SqlFunctionCategory funcType = SqlFunctionCategory.USER_DEFINED_FUNCTION; - final SqlIdentifier qualifiedName; - final Span s; - final SqlLiteral quantifier; - final List args; -} -{ - { - s = span(); - qualifiedName = new SqlIdentifier(unquotedIdentifier(), getPos()); - } - args = FunctionParameterList(ExprContext.ACCEPT_SUB_QUERY) { - quantifier = (SqlLiteral) args.get(0); - args.remove(0); - return createCall(qualifiedName, s.end(this), funcType, quantifier, args); - } -} - SqlNode DateaddFunctionCall() : { - final SqlFunctionCategory funcType = SqlFunctionCategory.USER_DEFINED_FUNCTION; final Span s; - final SqlIdentifier qualifiedName; - final TimeUnit unit; + final SqlOperator op; + final SqlIntervalQualifier unit; final List args; SqlNode e; } { - ( | | ) { - s = span(); - qualifiedName = new SqlIdentifier(unquotedIdentifier(), getPos()); - } - unit = TimeUnit() { - args = startList(new SqlIntervalQualifier(unit, null, getPos())); + ( { op = SqlLibraryOperators.DATE_PART; } + | { op = SqlLibraryOperators.DATEADD; } + | { op = SqlLibraryOperators.DATEDIFF; } + | { op = SqlLibraryOperators.DATEPART; } + ) + { s = span(); } + unit = TimeUnitOrName() { + args = startList(unit); } ( e = Expression(ExprContext.ACCEPT_SUB_QUERY) { @@ -65,7 +46,7 @@ SqlNode DateaddFunctionCall() : } )* { - return createCall(qualifiedName, s.end(this), funcType, null, args); + return op.createCall(s.end(this), args); } } @@ -174,6 +155,7 @@ SqlCreate SqlCreateTable(Span s, boolean replace) : < DATE_PART: "DATE_PART" > | < DATEADD: "DATEADD" > | < DATEDIFF: "DATEDIFF" > +| < DATEPART: "DATEPART" > | < NEGATE: "!" > | < TILDE: "~" > } @@ -204,5 +186,5 @@ void NullSafeEqual(List list, ExprContext exprContext, Span s) : checkNonQueryExpression(exprContext); list.add(new SqlParserUtil.ToTreeListItem(SqlLibraryOperators.NULL_SAFE_EQUAL, getPos())); } - Expression2b(ExprContext.ACCEPT_SUB_QUERY, list) + AddExpression2b(list, ExprContext.ACCEPT_SUB_QUERY) } diff --git a/babel/src/main/codegen/includes/parserPostgresqlImpls.ftl b/babel/src/main/codegen/includes/parserPostgresqlImpls.ftl new file mode 100644 index 00000000000..fee70a58d7b --- /dev/null +++ b/babel/src/main/codegen/includes/parserPostgresqlImpls.ftl @@ -0,0 +1,264 @@ +<#-- +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you 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. +--> + +/** SHOW ( | name) */ +SqlNode PostgresqlSqlShow() : +{ + final SqlIdentifier parameter; + final Span s; +} +{ + { s = span(); } + ( + parameter = PostgresqlTransactionIsolationLevel() +| + { + parameter = new SqlIdentifier(token.image.toLowerCase(Locale.ROOT), getPos()); + } + ) { return SqlShow.OPERATOR.createCall(null, s.end(this), parameter); } +} + +SqlIdentifier PostgresqlTransactionIsolationLevel() : +{ + final Span s; +} +{ + { s = span(); } { + return new SqlIdentifier("transaction_isolation", s.end(this)); + } +} + +/** + * SET [ SESSION | LOCAL ] configuration_parameter { TO | = } { value | 'value' | DEFAULT } + * SET [ SESSION | LOCAL ] TIME ZONE { value | 'value' | LOCAL | DEFAULT } + * SET [ SESSION | LOCAL ] (SCHEMA | NAMES | SEED) value + * value - Values can be specified as string constants, identifiers, numbers, or comma-separated lists of these + */ +SqlNode PostgresqlSqlSetOption() : +{ + SqlIdentifier name; + final SqlNode val; + String scope = null; + Span s; +} +{ + { s = span(); } + ( + { + s.add(this); + } + [ scope = PostgresqlOptionScope() ] + ( +