chore: Refine the project structure and readme (#1133)

This commit is contained in:
Jax Liu
2025-04-08 14:01:11 +08:00
committed by GitHub
parent f1742f81e4
commit 791340b5e8
556 changed files with 19 additions and 75400 deletions
-8
View File
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>io.takari.aether</groupId>
<artifactId>takari-local-repository</artifactId>
<version>0.11.3</version>
</extension>
</extensions>
-1
View File
@@ -1 +0,0 @@
-Xmx8192m
-159
View File
@@ -1,159 +0,0 @@
<?xml version="1.0"?>
<modernizer>
<violation>
<name>java/lang/Class.newInstance:()Ljava/lang/Object;</name>
<version>1.1</version>
<comment>Prefer Class.getConstructor().newInstance()</comment>
</violation>
<violation>
<name>java/lang/String."&lt;init&gt;":([B)V</name>
<version>1.1</version>
<comment>Prefer new String(byte[], Charset)</comment>
</violation>
<violation>
<name>java/lang/String.getBytes:()[B</name>
<version>1.1</version>
<comment>Prefer String.getBytes(Charset)</comment>
</violation>
<violation>
<name>java/lang/String.toLowerCase:()Ljava/lang/String;</name>
<version>1.1</version>
<comment>Prefer String.toLowerCase(java.util.Locale)</comment>
</violation>
<violation>
<name>java/lang/String.toUpperCase:()Ljava/lang/String;</name>
<version>1.1</version>
<comment>Prefer String.toUpperCase(java.util.Locale)</comment>
</violation>
<violation>
<!-- File.getPath() is the canonical way to convert File to its String representation suitable for passing to new File() -->
<name>java/io/File.toString:()Ljava/lang/String;</name>
<version>1.1</version>
<comment>Prefer File.getPath()</comment>
</violation>
<violation>
<name>com/google/common/primitives/Ints.checkedCast:(J)I</name>
<version>1.8</version>
<comment>Prefer Math.toIntExact(long)</comment>
</violation>
<violation>
<name>org/testng/Assert.assertEquals:(Ljava/lang/Iterable;Ljava/lang/Iterable;)V</name>
<version>1.8</version>
<comment>Use io.trino.testing.assertions.Assert.assertEquals due to TestNG #543</comment>
</violation>
<violation>
<name>org/testng/Assert.assertEquals:(Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/String;)V</name>
<version>1.8</version>
<comment>Use io.trino.testing.assertions.Assert.assertEquals due to TestNG #543</comment>
</violation>
<violation>
<name>org/testng/Assert.assertThrows:(Lorg/testng/Assert$ThrowingRunnable;)V</name>
<version>1.8</version>
<comment>Use AssertJ's assertThatThrownBy, see https://github.com/trinodb/trino/issues/5320 for rationale</comment>
</violation>
<violation>
<name>org/testng/Assert.assertThrows:(Ljava/lang/Class;Lorg/testng/Assert$ThrowingRunnable;)V</name>
<version>1.8</version>
<comment>Use AssertJ's assertThatThrownBy, see https://github.com/trinodb/trino/issues/5320 for rationale</comment>
</violation>
<violation>
<name>org/apache/hadoop/conf/Configuration."&lt;init&gt;":()V</name>
<version>1.1</version>
<comment>Prefer new Configuration(false)</comment>
</violation>
<violation>
<name>java/util/TimeZone.getTimeZone:(Ljava/lang/String;)Ljava/util/TimeZone;</name>
<version>1.8</version>
<comment>Avoid TimeZone.getTimeZone as it returns GMT for a zone not supported by the JVM. Use TimeZone.getTimeZone(ZoneId.of(..)) instead, or TimeZone.getTimeZone(..., false).</comment>
</violation>
<violation>
<name>org/joda/time/DateTimeZone.toTimeZone:()Ljava/util/TimeZone;</name>
<version>1.8</version>
<comment>Avoid DateTimeZone.toTimeZone as it returns GMT for a zone not supported by the JVM. Use TimeZone.getTimeZone(ZoneId.of(dtz.getId())) instead.</comment>
</violation>
<violation>
<name>com/esri/core/geometry/ogc/OGCGeometry.equals:(Lcom/esri/core/geometry/ogc/OGCGeometry;)Z</name>
<version>1.6</version>
<comment>Prefer OGCGeometry.Equals(OGCGeometry)</comment>
</violation>
<violation>
<name>com/esri/core/geometry/ogc/OGCGeometry.equals:(Ljava/lang/Object;)Z</name>
<version>1.6</version>
<comment>Prefer OGCGeometry.Equals(OGCGeometry)</comment>
</violation>
<violation>
<name>io/airlift/units/DataSize."&lt;init&gt;":(DLio/airlift/units/DataSize$Unit;)V</name>
<version>1.8</version>
<comment>Use io.airlift.units.DataSize.of(long, DataSize.Unit)</comment>
</violation>
<violation>
<name>io/airlift/units/DataSize.succinctDataSize:(DLio/airlift/units/DataSize$Unit;)Lio/airlift/units/DataSize;</name>
<version>1.8</version>
<comment>Use io.airlift.units.DataSize.of(long, DataSize.Unit).succinct() -- Note that succinct conversion only affects toString() results</comment>
</violation>
<violation>
<name>io/airlift/units/DataSize.getValue:()D</name>
<version>1.8</version>
<comment>Use io.airlift.units.DataSize.toBytes() and Unit.inBytes() for conversion</comment>
</violation>
<violation>
<name>io/airlift/units/DataSize.getValue:(Lio/airlift/units/DataSize$Unit;)D</name>
<version>1.8</version>
<comment>Use io.airlift.units.DataSize.toBytes() and Unit.inBytes() for conversion</comment>
</violation>
<violation>
<name>io/airlift/units/DataSize.roundTo:(Lio/airlift/units/DataSize$Unit;)J</name>
<version>1.8</version>
<comment>Method is deprecated for removal</comment>
</violation>
<violation>
<name>io/airlift/units/DataSize.convertTo:(Lio/airlift/units/DataSize$Unit;)Lio/airlift/units/DataSize;</name>
<version>1.8</version>
<comment>Use io.airlift.units.DataSize.to(DataSize.Unit)</comment>
</violation>
<violation>
<name>io/airlift/units/DataSize.convertToMostSuccinctDataSize:()Lio/airlift/units/DataSize;</name>
<version>1.8</version>
<comment>Use io.airlift.units.DataSize.succinct()</comment>
</violation>
<violation>
<name>io/airlift/testing/Closeables.closeQuietly:([Ljava/io/Closeable;)V</name>
<version>1.0</version>
<comment>Use Closeables.closeAll() or Closer.</comment>
</violation>
<violation>
<name>com/google/inject/util/Modules.combine:(Ljava/lang/Iterable;)Lcom/google/inject/Module;</name>
<version>1.8</version>
<comment>Use io.airlift.configuration.ConfigurationAwareModule.combine</comment>
</violation>
<violation>
<name>com/google/inject/util/Modules.combine:([Lcom/google/inject/Module;)Lcom/google/inject/Module;</name>
<version>1.8</version>
<comment>Use io.airlift.configuration.ConfigurationAwareModule.combine</comment>
</violation>
</modernizer>
BIN
View File
Binary file not shown.
-1
View File
@@ -1 +0,0 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/apache-maven-3.9.8-bin.zip
+3 -3
View File
@@ -1,6 +1,6 @@
# Wren Core in Python
# Wren Core Python binding
Here is a dependency package for Python. It is a wrapper for the Rust package [wren-core](../wren-core). The Rust package is compiled to a Python package and can be used in Python.
This is a python binding for [wren-core](../wren-core). It uses [PyO3](https://github.com/PyO3/pyo3) to build the required wheel for [ibis-server](../ibis-server/).
## Developer Guide
@@ -12,7 +12,7 @@ Here is a dependency package for Python. It is a wrapper for the Rust package [w
- Install [casey/just](https://github.com/casey/just)
### Test and build
After install `casey/just`, you can use the following command to build or test:
- Execute `just install` to create Python venv and install dependencies.
- **Important**: Before testing Python, you need to build the Rust package by running `just develop`.
- Use `just test-rs` to test Rust only, and `just test-py` to test Python only.
+16 -12
View File
@@ -1,32 +1,36 @@
# Wren Core Module
This is just a very early version of transforming SQL with DataFusion. The main program is a simple use case demonstrating how to use the mdl library.
The Wren Core module serves as the semantic core of the Wren engine. To understand the concept of the Wren engine, refer to the [Wren engine documentation](https://docs.getwren.ai/oss/engine/concept/what_is_semantics).
There are some modules:
This module is utilized by the API v3 of the ibis-server for SQL planning. Additionally, there is another module for Python bindings, [wren-core-py](../wren-core-py/), which is also used by the [ibis-server](../ibis-server/).
- mdl: The main entry point for using Wren modeling.
- logical_plan: The rewrite rule based on the logical planner of DataFusion.
## How to Test / Build
# How to Test / Build
- Run Test
Currently, the test cases are placed in `src/mdl/mod.rs`
- **Run Tests**:
- Most unit test cases are located in `src/mdl/mod.rs`.
- SQL end-to-end tests are executed using `sqllogictests`.
You can run all tests with the following command:
```
cargo test
```
# Coding Style
Please format your code with `rustfmt` and `taplo` before submitting a pull request.
## Coding Style
## Format with rustfmt
Please ensure your code is properly formatted before submitting a pull request. Use `rustfmt` for Rust files and `taplo` for formatting TOML files.
### Format with rustfmt
Run the following command to format Rust code:
```
cargo fmt
```
## Format toml with taplo
### Format TOML with taplo
Install `taplo-cli` and format TOML files with the following commands:
```
cargo install taplo-cli --locked
-21
View File
@@ -1,21 +0,0 @@
FROM eclipse-temurin:21
LABEL maintainer="https://www.canner.io/"
WORKDIR /usr/src/app
RUN \
apt update && \
apt -y install curl gpg lsb-release && \
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg && \
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
apt update && \
apt -y install postgresql-client-13
ARG WREN_VERSION
ENV ENV_WREN_VERSION=${WREN_VERSION}
ENV WREN_JAR=wren-server-${ENV_WREN_VERSION}-executable.jar
COPY ${WREN_JAR} ./
COPY entrypoint.sh ./
RUN chmod +x ./entrypoint.sh
CMD ./entrypoint.sh ${WREN_JAR} ${MAX_HEAP_SIZE} ${MIN_HEAP_SIZE}
-28
View File
@@ -1,28 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SOURCE_DIR="../"
# Retrieve the script directory.
SCRIPT_DIR="${BASH_SOURCE%/*}"
cd ${SCRIPT_DIR}
# Move to the root directory to run maven for current version.
pushd ${SOURCE_DIR}
WREN_VERSION=$(./mvnw --quiet help:evaluate -Dexpression=project.version -DforceStdout)
popd
WORK_DIR="$(mktemp -d)"
cp ${SOURCE_DIR}wren-server/target/wren-server-${WREN_VERSION}-executable.jar ${WORK_DIR}
cp ./entrypoint.sh ${WORK_DIR}
CONTAINER="wren-engine:${WREN_VERSION}"
docker build ${WORK_DIR} --pull --platform linux/amd64 -f Dockerfile -t ${CONTAINER}-amd64 --build-arg "WREN_VERSION=${WREN_VERSION}"
docker build ${WORK_DIR} --pull --platform linux/arm64 -f Dockerfile -t ${CONTAINER}-arm64 --build-arg "WREN_VERSION=${WREN_VERSION}"
rm -r ${WORK_DIR}
docker image inspect -f '🚀 Built {{.RepoTags}} {{.Id}}' ${CONTAINER}-amd64
docker image inspect -f '🚀 Built {{.RepoTags}} {{.Id}}' ${CONTAINER}-arm64
-13
View File
@@ -1,13 +0,0 @@
services:
ibis-server:
image: ghcr.io/canner/wren-engine-ibis:latest
ports:
- "8000:8000"
environment:
WREN_ENGINE_ENDPOINT: http://java-engine:8080
java-engine:
image: ghcr.io/canner/wren-engine:latest
ports:
- "8080:8080"
volumes:
- ./etc:/usr/src/app/etc
-8
View File
@@ -1,8 +0,0 @@
#!/bin/bash
export ENV_MAX_HEAP_SIZE=$2
export ENV_MIN_HEAP_SIZE=$3
# Required add-opens=java.nio=ALL-UNNAMED for Apache arrow in the Snowflake
java -Xmx${ENV_MAX_HEAP_SIZE:-"512m"} -Xms${ENV_MIN_HEAP_SIZE:-"64m"} -Dconfig=etc/config.properties \
--add-opens=java.base/java.nio=ALL-UNNAMED \
-jar $1
-1
View File
@@ -1 +0,0 @@
node.environment=test
Vendored
-236
View File
@@ -1,236 +0,0 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# 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.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
#
# Look for the Apple JDKs first to preserve the existing behaviour, and then look
# for the new JDKs provided by Oracle.
#
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
#
# Oracle JDKs
#
export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
#
# Apple JDKs
#
export JAVA_HOME=`/usr/libexec/java_home`
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Migwn, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
local basedir=$(pwd)
local wdir=$(pwd)
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
wdir=$(cd "$wdir/.."; pwd)
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
# avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in $@
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
-668
View File
@@ -1,668 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.airlift</groupId>
<artifactId>airbase</artifactId>
<version>241</version>
</parent>
<groupId>io.wren</groupId>
<artifactId>wren-root</artifactId>
<version>0.15.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>WrenEngine</name>
<description>WrenEngine</description>
<inceptionYear>2022</inceptionYear>
<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<modules>
<module>trino-parser</module>
<module>wren-base</module>
<module>wren-main</module>
<module>wren-server</module>
<module>wren-tests</module>
</modules>
<scm>
<tag>HEAD</tag>
</scm>
<distributionManagement>
<repository>
<id>maven-repo.cannerdata.com</id>
<name>Canner Repository</name>
<url>s3://maven-repo.cannerdata.com/release</url>
</repository>
<snapshotRepository>
<id>maven-repo.cannerdata.com</id>
<name>Canner Repository</name>
<url>s3://maven-repo.cannerdata.com/snapshot</url>
</snapshotRepository>
</distributionManagement>
<properties>
<project.build.targetJdk>21</project.build.targetJdk>
<air.main.basedir>${project.basedir}</air.main.basedir>
<air.check.skip-spotbugs>true</air.check.skip-spotbugs>
<air.check.skip-pmd>true</air.check.skip-pmd>
<air.check.skip-jacoco>true</air.check.skip-jacoco>
<air.check.fail-duplicate-finder>false</air.check.fail-duplicate-finder>
<air.check.fail-license>false</air.check.fail-license>
<air.java.version>21.0.1</air.java.version>
<air.modernizer.java-version>8</air.modernizer.java-version>
<dep.antlr.version>4.13.2</dep.antlr.version>
<dep.airlift.version>269</dep.airlift.version>
<dep.packaging.version>${dep.airlift.version}</dep.packaging.version>
<dep.drift.version>1.22</dep.drift.version>
<dep.testcontainers.version>1.20.6</dep.testcontainers.version>
<dep.errorprone.version>2.37.0</dep.errorprone.version>
<dep.plugin.failsafe.version>${dep.plugin.surefire.version}</dep.plugin.failsafe.version>
<netty.version>4.1.45.Final</netty.version>
<!--
America/Bahia_Banderas has:
- offset change since 1970 (offset Jan 1970: -08:00, offset Jan 2018: -06:00)
- DST (e.g. at 2017-04-02 02:00:00 clocks turned forward 1 hour; 2017-10-29 02:00:00 clocks turned backward 1 hour)
- has forward offset change on first day of epoch (1970-01-01 00:00:00 clocks turned forward 1 hour)
- had forward change at midnight (1970-01-01 00:00:00 clocks turned forward 1 hour)
-->
<air.test.timezone>America/Bahia_Banderas</air.test.timezone>
<air.test.parallel>methods</air.test.parallel>
<air.test.thread-count>2</air.test.thread-count>
<!-- Be conservative about memory allotment, because tests start background process (e.g. docker containers) -->
<air.test.jvmsize>3g</air.test.jvmsize>
<air.javadoc.lint>-missing</air.javadoc.lint>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-bom</artifactId>
<version>3.48.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${dep.testcontainers.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.18.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.18.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.18.3</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<version>${dep.errorprone.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>failureaccess</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>4.30.1</version>
</dependency>
<dependency>
<groupId>com.hubspot.jinjava</groupId>
<artifactId>jinjava</artifactId>
<version>2.7.4</version>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>6.3.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>bootstrap</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>concurrent</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>configuration</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>event</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>http-client</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>http-server</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>jaxrs</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>json</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>log</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>log-manager</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>node</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>stats</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>testing</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>trace-token</artifactId>
<version>${dep.airlift.version}</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>units</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv</artifactId>
<version>1.30.0</version>
</dependency>
<dependency>
<groupId>io.wren</groupId>
<artifactId>trino-parser</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.wren</groupId>
<artifactId>wren-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.wren</groupId>
<artifactId>wren-main</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.wren</groupId>
<artifactId>wren-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.wren</groupId>
<artifactId>wren-tests</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.wren</groupId>
<artifactId>wren-validation</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.17.4</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>${dep.antlr.version}</version>
</dependency>
<!-- TODO: move this to Airbase -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.16</version>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<version>3.49.1</version>
</dependency>
<dependency>
<groupId>org.duckdb</groupId>
<artifactId>duckdb_jdbc</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>26.0.2</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.5</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${dep.testcontainers.version}</version>
<exclusions>
<exclusion>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>${dep.antlr.version}</version>
<configuration>
<visitor>true</visitor>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
</plugin>
<plugin>
<groupId>org.skife.maven</groupId>
<artifactId>really-executable-jar-maven-plugin</artifactId>
<version>2.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.5.0</version>
</plugin>
<plugin>
<groupId>io.airlift.drift</groupId>
<artifactId>drift-maven-plugin</artifactId>
<version>${dep.drift.version}</version>
</plugin>
<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
<configuration>
<violationsFiles>
<violationsFile>${air.main.basedir}/.mvn/modernizer/violations.xml</violationsFile>
</violationsFiles>
<exclusionPatterns>
<exclusionPattern>org/joda/time/.*</exclusionPattern>
</exclusionPatterns>
<exclusions>
<!-- getOnlyElement is more readable than the stream analogue -->
<exclusion>com/google/common/collect/Iterables.getOnlyElement:(Ljava/lang/Iterable;)Ljava/lang/Object;</exclusion>
<exclusion>com/google/common/collect/Iterables.getOnlyElement:(Ljava/lang/Iterable;Ljava/lang/Object;)Ljava/lang/Object;</exclusion>
<!-- getLast has lower complexity for array based lists than the stream analogue (O(1) vs O(log(N)) -->
<exclusion>com/google/common/collect/Iterables.getLast:(Ljava/lang/Iterable;)Ljava/lang/Object;</exclusion>
<exclusion>com/google/common/collect/Iterables.getLast:(Ljava/lang/Iterable;Ljava/lang/Object;)Ljava/lang/Object;</exclusion>
<!-- TODO: requires getting to common understanding which of those we want to enable -->
<exclusion>com/google/common/collect/Iterables.transform:(Ljava/lang/Iterable;Lcom/google/common/base/Function;)Ljava/lang/Iterable;</exclusion>
<exclusion>com/google/common/collect/Lists.transform:(Ljava/util/List;Lcom/google/common/base/Function;)Ljava/util/List;</exclusion>
<exclusion>com/google/common/collect/Iterables.isEmpty:(Ljava/lang/Iterable;)Z</exclusion>
<exclusion>com/google/common/collect/Iterables.concat:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/lang/Iterable;</exclusion>
<exclusion>com/google/common/collect/Iterables.concat:(Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/lang/Iterable;</exclusion>
<exclusion>com/google/common/collect/Iterables.concat:(Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/lang/Iterable;</exclusion>
<exclusion>com/google/common/collect/Iterables.concat:(Ljava/lang/Iterable;)Ljava/lang/Iterable;</exclusion>
<exclusion>com/google/common/collect/Iterables.all:(Ljava/lang/Iterable;Lcom/google/common/base/Predicate;)Z</exclusion>
<exclusion>com/google/common/collect/Iterables.any:(Ljava/lang/Iterable;Lcom/google/common/base/Predicate;)Z</exclusion>
<exclusion>com/google/common/collect/Iterables.skip:(Ljava/lang/Iterable;I)Ljava/lang/Iterable;</exclusion>
<exclusion>com/google/common/collect/Iterables.limit:(Ljava/lang/Iterable;I)Ljava/lang/Iterable;</exclusion>
<exclusion>com/google/common/collect/Iterables.get:(Ljava/lang/Iterable;I)Ljava/lang/Object;</exclusion>
<exclusion>com/google/common/collect/Iterables.getFirst:(Ljava/lang/Iterable;Ljava/lang/Object;)Ljava/lang/Object;</exclusion>
<exclusion>com/google/common/collect/Iterables.getLast:(Ljava/lang/Iterable;)Ljava/lang/Object;</exclusion>
<exclusion>com/google/common/collect/Iterables.cycle:(Ljava/lang/Iterable;)Ljava/lang/Iterable;</exclusion>
<exclusion>com/google/common/collect/Iterables.cycle:([Ljava/lang/Object;)Ljava/lang/Iterable;</exclusion>
<!-- com.google.common.io.BaseEncoding.base64 provides more reach interfaces than java.util.Base64 -->
<exclusion>com/google/common/io/BaseEncoding.base64:()Lcom/google/common/io/BaseEncoding;</exclusion>
<!-- disable default modernizer violation -->
<exclusion>com/google/inject/Provider</exclusion>
</exclusions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<configuration>
<rules>
<requireUpperBoundDeps>
<excludes combine.children="append">
<!-- TODO: fix this in Airlift resolver -->
<exclude>org.codehaus.plexus:plexus-utils</exclude>
<exclude>com.google.guava:guava</exclude>
<exclude>com.fasterxml.jackson.core:jackson-core</exclude>
<exclude>com.google.j2objc:j2objc-annotations</exclude>
</excludes>
</requireUpperBoundDeps>
<bannedDependencies>
<excludes combine.children="append">
<!-- We don't use log4j2, additionally versions < 2.15.0 are vulnerable to the RCE Log4Shell (CVE-2021-44228) -->
<exclude>org.apache.logging.log4j:log4j-core</exclude>
<!-- 1.x versions are banned due to https://www.cve.org/CVERecord?id=CVE-2022-1471 -->
<exclude>org.yaml:snakeyaml</exclude>
<!-- use Guice version -->
<exclude>javax.inject:javax.inject</exclude>
<!-- use Jakarta version -->
<exclude>javax.annotation:javax.annotation-api</exclude>
</excludes>
<includes combine.children="append">
<!-- 2.x versions are not affected by CVE-2022-1471 -->
<include>org.yaml:snakeyaml:2.+</include>
</includes>
</bannedDependencies>
<requireProfileIdsExist />
<requirePropertyDiverges>
<property>project.description</property>
</requirePropertyDiverges>
</rules>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<preparationGoals>clean verify -DskipTests</preparationGoals>
</configuration>
</plugin>
<plugin>
<groupId>ca.vanzyl.provisio.maven.plugins</groupId>
<artifactId>provisio-maven-plugin</artifactId>
<version>1.1.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>io.trino</groupId>
<artifactId>trino-maven-plugin</artifactId>
<version>15</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>ca.vanzyl.provisio.maven.plugins</groupId>
<artifactId>provisio-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration combine.children="append">
<fork>false</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<java.util.logging.SimpleFormatter.format>%1$tY-%1$tm-%1$tdT%1$tH:%1$tM:%1$tS.%1$tL%1$tz %4$s %3$s %5$s%6$s%n</java.util.logging.SimpleFormatter.format>
</systemPropertyVariables>
<argLine>
@{argLine}
<!-- Required for Apache arrow in the Snowflake (See https://arrow.apache.org/docs/java/install.html#java-compatibility) -->
--add-opens=java.base/java.nio=ALL-UNNAMED
</argLine>
<failIfNoTests>false</failIfNoTests>
<includes>
<!-- Tests classes should start with "Test", but we do also want to include tests incorrectly named, with "Test" at the end -->
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/Benchmark*.java</include>
</includes>
<excludes>
<exclude>**/*jmhTest*.java</exclude>
<exclude>**/*jmhType*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.kuali.maven.wagons</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>1.2.1</version>
</extension>
</extensions>
</build>
<profiles>
<profile>
<id>errorprone-compiler</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!--suppress MavenModelInspection -->
<configuration combine.children="merge">
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<!-- TODO enable more checks, i.e. remove "-XepDisableAllChecks" -->
<arg>-Xplugin:ErrorProne
-XepExcludedPaths:.*/target/generated-(|test-)sources/.*
-XepDisableAllChecks
-Xep:ArrayEquals:ERROR
-Xep:ArrayHashCode:ERROR
-Xep:ArrayToString:ERROR
-Xep:ArraysAsListPrimitiveArray:ERROR
-Xep:BadInstanceof:ERROR
-Xep:BadShiftAmount:ERROR
-Xep:BoxedPrimitiveConstructor:ERROR
-Xep:ClassCanBeStatic:ERROR
-Xep:CompareToZero:ERROR
-Xep:ComparingThisWithNull:ERROR
-Xep:EqualsIncompatibleType:ERROR
-Xep:FallThrough:ERROR
-Xep:FormatString:ERROR
-Xep:GetClassOnAnnotation:ERROR
-Xep:GetClassOnClass:ERROR
-Xep:IdentityBinaryExpression:ERROR
-Xep:ImmutableSetForContains:ERROR
-Xep:InconsistentHashCode:ERROR
-Xep:InjectOnConstructorOfAbstractClass:ERROR
-Xep:MissingCasesInEnumSwitch:ERROR
-Xep:MissingOverride:ERROR
-Xep:MisusedWeekYear:ERROR
-Xep:NullOptional:ERROR
-Xep:ObjectToString:ERROR
-Xep:OptionalEquality:ERROR
-Xep:OptionalMapUnusedValue:ERROR
-Xep:PreconditionsInvalidPlaceholder:ERROR
-Xep:ReturnValueIgnored:ERROR
-Xep:StaticQualifiedUsingExpression:ERROR
-Xep:ThrowIfUncheckedKnownChecked:ERROR
-Xep:UnnecessaryCheckNotNull:ERROR
-Xep:UnnecessaryMethodReference:ERROR
-Xep:UnnecessaryOptionalGet:ERROR
-Xep:UnusedVariable:ERROR
-Xep:UseEnumSwitch:ERROR
-Xep:ZoneIdOfZ:ERROR</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${dep.errorprone.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
-77
View File
@@ -1,77 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.wren</groupId>
<artifactId>wren-root</artifactId>
<version>0.15.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>trino-parser</artifactId>
<name>trino-parser</name>
<description>Trino - Parser</description>
<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>slice</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>
<!-- for testing -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
File diff suppressed because it is too large Load Diff
@@ -1,64 +0,0 @@
/*
* Licensed 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.
*/
//TODO: consider using the SQL grammar for this
grammar TypeCalculation;
// workaround for:
// https://github.com/antlr/antlr4/issues/118
typeCalculation
: expression EOF
;
expression
: NULL #nullLiteral
| INTEGER_VALUE #numericLiteral
| binaryFunctionName '(' left=expression ',' right=expression ')' #binaryFunction
| IDENTIFIER #identifier
| '(' expression ')' #parenthesizedExpression
| operator=(MINUS | PLUS) expression #arithmeticUnary
| left=expression operator=(ASTERISK | SLASH) right=expression #arithmeticBinary
| left=expression operator=(PLUS | MINUS) right=expression #arithmeticBinary
;
binaryFunctionName
: name=(MAX | MIN)
;
PLUS: '+';
MINUS: '-';
ASTERISK: '*';
SLASH: '/';
NULL: 'NULL';
MIN: 'MIN';
MAX: 'MAX';
IDENTIFIER
: (LETTER | '_') (LETTER | DIGIT | '_' )*
;
INTEGER_VALUE
: DIGIT+
;
fragment DIGIT
: ('0'..'9')
;
fragment LETTER
: [A-Za-z]
;
WS
: [ \r\n\t]+ -> channel(HIDDEN)
;
File diff suppressed because it is too large Load Diff
@@ -1,367 +0,0 @@
package io.trino.sql;
import com.google.common.collect.ImmutableList;
import io.trino.sql.parser.ParsingOptions;
import io.trino.sql.parser.SqlParser;
import io.trino.sql.tree.AliasedRelation;
import io.trino.sql.tree.AllColumns;
import io.trino.sql.tree.CoalesceExpression;
import io.trino.sql.tree.ComparisonExpression;
import io.trino.sql.tree.DereferenceExpression;
import io.trino.sql.tree.Expression;
import io.trino.sql.tree.FunctionCall;
import io.trino.sql.tree.GroupBy;
import io.trino.sql.tree.Identifier;
import io.trino.sql.tree.Join;
import io.trino.sql.tree.JoinCriteria;
import io.trino.sql.tree.JoinOn;
import io.trino.sql.tree.LogicalExpression;
import io.trino.sql.tree.LongLiteral;
import io.trino.sql.tree.Node;
import io.trino.sql.tree.NullLiteral;
import io.trino.sql.tree.Offset;
import io.trino.sql.tree.OrderBy;
import io.trino.sql.tree.QualifiedName;
import io.trino.sql.tree.Query;
import io.trino.sql.tree.QueryBody;
import io.trino.sql.tree.QuerySpecification;
import io.trino.sql.tree.Relation;
import io.trino.sql.tree.Row;
import io.trino.sql.tree.SearchedCaseExpression;
import io.trino.sql.tree.Select;
import io.trino.sql.tree.SelectItem;
import io.trino.sql.tree.SingleColumn;
import io.trino.sql.tree.SortItem;
import io.trino.sql.tree.StringLiteral;
import io.trino.sql.tree.SubscriptExpression;
import io.trino.sql.tree.Table;
import io.trino.sql.tree.TableSubquery;
import io.trino.sql.tree.Unnest;
import io.trino.sql.tree.Values;
import io.trino.sql.tree.WhenClause;
import io.trino.sql.tree.WindowDefinition;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static io.trino.sql.parser.ParsingOptions.DecimalLiteralTreatment.AS_DOUBLE;
import static io.trino.sql.tree.BooleanLiteral.FALSE_LITERAL;
import static io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL;
import static java.util.Arrays.asList;
public final class QueryUtil
{
private QueryUtil() {}
public static Identifier identifier(String name)
{
return new Identifier(name);
}
public static Identifier quotedIdentifier(String name)
{
return new Identifier(name, true);
}
public static Expression nameReference(String first, String... rest)
{
return DereferenceExpression.from(QualifiedName.of(first, rest));
}
public static SelectItem unaliasedName(String name)
{
return new SingleColumn(identifier(name));
}
public static SelectItem aliasedName(String name, String alias)
{
return new SingleColumn(identifier(name), identifier(alias));
}
public static SubscriptExpression subscriptExpression(Expression name, String index)
{
return new SubscriptExpression(name, new LongLiteral(index));
}
public static Select selectList(Expression... expressions)
{
return selectList(asList(expressions));
}
public static Select selectList(List<Expression> expressions)
{
ImmutableList.Builder<SelectItem> items = ImmutableList.builder();
for (Expression expression : expressions) {
items.add(new SingleColumn(expression));
}
return new Select(false, items.build());
}
public static Select selectListDistinct(List<Expression> expressions)
{
ImmutableList.Builder<SelectItem> items = ImmutableList.builder();
for (Expression expression : expressions) {
items.add(new SingleColumn(expression));
}
return new Select(true, items.build());
}
public static Select selectList(List<Expression> expressions, List<String> aliases)
{
ImmutableList.Builder<SelectItem> items = ImmutableList.builder();
for (int i = 0; i < expressions.size(); i++) {
items.add(new SingleColumn(expressions.get(i), identifier(aliases.get(i))));
}
return new Select(false, items.build());
}
public static Select selectList(SelectItem... items)
{
return new Select(false, ImmutableList.copyOf(items));
}
public static Select selectAll(List<SelectItem> items)
{
return new Select(false, items);
}
public static Table table(QualifiedName name)
{
return new Table(name);
}
public static Unnest unnest(Expression... expressions)
{
return new Unnest(asList(expressions), false);
}
public static Join leftJoin(Relation left, Relation right, JoinCriteria joinCriteria)
{
return new Join(Join.Type.LEFT, left, right, Optional.ofNullable(joinCriteria));
}
public static Join crossJoin(Relation left, Relation right)
{
return new Join(Join.Type.CROSS, left, right, Optional.empty());
}
public static Join implicitJoin(Relation left, Relation right)
{
return new Join(Join.Type.IMPLICIT, left, right, Optional.empty());
}
public static JoinOn joinOn(Expression conditionSql)
{
return new JoinOn(conditionSql);
}
public static ComparisonExpression getConditionNode(String condition)
{
SqlParser sqlParser = new SqlParser();
Query statement = (Query) sqlParser.createStatement("SELECT " + condition, new ParsingOptions(AS_DOUBLE));
return (ComparisonExpression)
((SingleColumn) ((QuerySpecification) statement.getQueryBody()).getSelect().getSelectItems().get(0)).getExpression();
}
public static Relation subquery(Query query)
{
return new TableSubquery(query);
}
public static SortItem ascending(String name)
{
return new SortItem(identifier(name), SortItem.Ordering.ASCENDING, SortItem.NullOrdering.UNDEFINED);
}
public static Expression logicalAnd(Expression left, Expression right)
{
return LogicalExpression.and(left, right);
}
public static Expression equal(Expression left, Expression right)
{
return new ComparisonExpression(ComparisonExpression.Operator.EQUAL, left, right);
}
public static Expression caseWhen(Expression operand, Expression result)
{
return new SearchedCaseExpression(ImmutableList.of(new WhenClause(operand, result)), Optional.empty());
}
public static Expression functionCall(String name, List<Expression> arguments)
{
return new FunctionCall(QualifiedName.of(name), ImmutableList.copyOf(arguments));
}
public static Expression functionCall(String name, Expression... arguments)
{
return new FunctionCall(QualifiedName.of(name), ImmutableList.copyOf(arguments));
}
public static Values values(Row... row)
{
return new Values(ImmutableList.copyOf(row));
}
public static Row row(Expression... values)
{
return new Row(ImmutableList.copyOf(values));
}
public static Relation aliased(Relation relation, String alias)
{
return new AliasedRelation(relation, identifier(alias), null);
}
public static Relation aliased(Relation relation, String alias, List<String> columnAliases)
{
return new AliasedRelation(
relation,
identifier(alias),
columnAliases.stream()
.map(QueryUtil::identifier)
.collect(Collectors.toList()));
}
public static SelectItem aliasedNullToEmpty(String column, String alias)
{
return new SingleColumn(new CoalesceExpression(identifier(column), new StringLiteral("")), identifier(alias));
}
public static OrderBy ordering(SortItem... items)
{
return new OrderBy(ImmutableList.copyOf(items));
}
public static Query simpleQuery(Select select)
{
return query(new QuerySpecification(
select,
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
ImmutableList.of(),
Optional.empty(),
Optional.empty(),
Optional.empty()));
}
public static Query simpleQuery(Select select, Relation from)
{
return simpleQuery(select, from, Optional.empty(), Optional.empty());
}
public static Query simpleQuery(Select select, Relation from, OrderBy orderBy)
{
return simpleQuery(select, from, Optional.empty(), Optional.of(orderBy));
}
public static Query simpleQuery(Select select, Relation from, Expression where)
{
return simpleQuery(select, from, Optional.of(where), Optional.empty());
}
public static Query simpleQuery(Select select, Relation from, Expression where, OrderBy orderBy)
{
return simpleQuery(select, from, Optional.of(where), Optional.of(orderBy));
}
public static Query simpleQuery(Select select, Relation from, Optional<Expression> where, Optional<OrderBy> orderBy)
{
return simpleQuery(select, from, where, Optional.empty(), Optional.empty(), orderBy, Optional.empty(), Optional.empty());
}
public static Query simpleQuery(
Select select,
Relation from,
Optional<Expression> where,
Optional<GroupBy> groupBy,
Optional<Expression> having,
Optional<OrderBy> orderBy,
Optional<Offset> offset,
Optional<Node> limit)
{
return simpleQuery(select, from, where, groupBy, having, ImmutableList.of(), orderBy, offset, limit);
}
public static Query simpleQuery(
Select select,
Relation from,
Optional<Expression> where,
Optional<GroupBy> groupBy,
Optional<Expression> having,
List<WindowDefinition> windows,
Optional<OrderBy> orderBy,
Optional<Offset> offset,
Optional<Node> limit)
{
return query(new QuerySpecification(
select,
Optional.of(from),
where,
groupBy,
having,
windows,
orderBy,
offset,
limit));
}
public static Query singleValueQuery(String columnName, String value)
{
Relation values = values(row(new StringLiteral((value))));
return simpleQuery(
selectList(new AllColumns()),
aliased(values, "t", ImmutableList.of(columnName)));
}
public static Query singleValueQuery(String columnName, boolean value)
{
Relation values = values(row(value ? TRUE_LITERAL : FALSE_LITERAL));
return simpleQuery(
selectList(new AllColumns()),
aliased(values, "t", ImmutableList.of(columnName)));
}
// TODO pass column types
public static Query emptyQuery(List<String> columns)
{
Select select = selectList(columns.stream()
.map(column -> new SingleColumn(new NullLiteral(), QueryUtil.identifier(column)))
.toArray(SelectItem[]::new));
Optional<Expression> where = Optional.of(FALSE_LITERAL);
return query(new QuerySpecification(
select,
Optional.empty(),
where,
Optional.empty(),
Optional.empty(),
ImmutableList.of(),
Optional.empty(),
Optional.empty(),
Optional.empty()));
}
public static Query query(QueryBody body)
{
return new Query(
Optional.empty(),
body,
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static QualifiedName getQualifiedName(Expression expression)
{
if (expression instanceof DereferenceExpression) {
return DereferenceExpression.getQualifiedName((DereferenceExpression) expression);
}
if (expression instanceof Identifier) {
return QualifiedName.of(ImmutableList.of((Identifier) expression));
}
return null;
}
}
@@ -1,153 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql;
import com.google.common.collect.ImmutableSet;
import io.trino.sql.parser.ParsingException;
import io.trino.sql.parser.ParsingOptions;
import io.trino.sql.parser.SqlBaseLexer;
import io.trino.sql.parser.SqlParser;
import io.trino.sql.tree.Identifier;
import org.antlr.v4.runtime.Vocabulary;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.lang.String.format;
public final class ReservedIdentifiers
{
private static final Pattern IDENTIFIER = Pattern.compile("'([A-Z_]+)'");
private static final Pattern TABLE_ROW = Pattern.compile("``([A-Z_]+)``.*");
private static final String TABLE_PREFIX = "============================== ";
private static final SqlParser PARSER = new SqlParser();
private ReservedIdentifiers() {}
@SuppressWarnings("CallToPrintStackTrace")
public static void main(String[] args)
{
if ((args.length == 2) && args[0].equals("validateDocs")) {
try {
validateDocs(Paths.get(args[1]));
}
catch (Throwable t) {
t.printStackTrace();
System.exit(100);
}
}
else {
for (String name : reservedIdentifiers()) {
System.out.println(name);
}
}
}
private static void validateDocs(Path path)
throws IOException
{
System.out.println("Validating " + path);
List<String> lines = Files.readAllLines(path);
if (lines.stream().filter(s -> s.startsWith(TABLE_PREFIX)).count() != 3) {
throw new RuntimeException("Failed to find exactly one table");
}
Iterator<String> iterator = lines.iterator();
// find table and skip header
while (!iterator.next().startsWith(TABLE_PREFIX)) {
// skip
}
if (iterator.next().startsWith(TABLE_PREFIX)) {
throw new RuntimeException("Expected to find a header line");
}
if (!iterator.next().startsWith(TABLE_PREFIX)) {
throw new RuntimeException("Found multiple header lines");
}
Set<String> reserved = reservedIdentifiers();
Set<String> found = new HashSet<>();
while (true) {
String line = iterator.next();
if (line.startsWith(TABLE_PREFIX)) {
break;
}
Matcher matcher = TABLE_ROW.matcher(line);
if (!matcher.matches()) {
throw new RuntimeException("Invalid table line: " + line);
}
String name = matcher.group(1);
if (!reserved.contains(name)) {
throw new RuntimeException("Documented identifier is not reserved: " + name);
}
if (!found.add(name)) {
throw new RuntimeException("Duplicate documented identifier: " + name);
}
}
for (String name : reserved) {
if (!found.contains(name)) {
throw new RuntimeException("Reserved identifier is not documented: " + name);
}
}
System.out.println(format("Validated %s reserved identifiers", reserved.size()));
}
public static Set<String> reservedIdentifiers()
{
return sqlKeywords().stream()
.filter(ReservedIdentifiers::reserved)
.sorted()
.collect(toImmutableSet());
}
public static Set<String> sqlKeywords()
{
ImmutableSet.Builder<String> names = ImmutableSet.builder();
Vocabulary vocabulary = SqlBaseLexer.VOCABULARY;
for (int i = 0; i <= vocabulary.getMaxTokenType(); i++) {
String name = nullToEmpty(vocabulary.getLiteralName(i));
Matcher matcher = IDENTIFIER.matcher(name);
if (matcher.matches()) {
names.add(matcher.group(1));
}
}
return names.build();
}
public static boolean reserved(String name)
{
try {
return !(PARSER.createExpression(name, new ParsingOptions()) instanceof Identifier);
}
catch (ParsingException ignored) {
return true;
}
}
}
@@ -1,159 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql;
import io.trino.sql.SqlFormatter.Dialect;
import io.trino.sql.tree.AnchorPattern;
import io.trino.sql.tree.AstVisitor;
import io.trino.sql.tree.EmptyPattern;
import io.trino.sql.tree.ExcludedPattern;
import io.trino.sql.tree.Node;
import io.trino.sql.tree.OneOrMoreQuantifier;
import io.trino.sql.tree.PatternAlternation;
import io.trino.sql.tree.PatternConcatenation;
import io.trino.sql.tree.PatternPermutation;
import io.trino.sql.tree.PatternVariable;
import io.trino.sql.tree.QuantifiedPattern;
import io.trino.sql.tree.RangeQuantifier;
import io.trino.sql.tree.RowPattern;
import io.trino.sql.tree.ZeroOrMoreQuantifier;
import io.trino.sql.tree.ZeroOrOneQuantifier;
import static io.trino.sql.ExpressionFormatter.formatExpression;
import static java.lang.String.format;
import static java.util.stream.Collectors.joining;
public final class RowPatternFormatter
{
private RowPatternFormatter() {}
public static String formatPattern(RowPattern pattern, Dialect dialect)
{
return new Formatter(dialect).process(pattern, null);
}
public static class Formatter
extends AstVisitor<String, Void>
{
private final Dialect dialect;
public Formatter(Dialect dialect)
{
this.dialect = dialect;
}
@Override
protected String visitNode(Node node, Void context)
{
throw new UnsupportedOperationException();
}
@Override
protected String visitRowPattern(RowPattern node, Void context)
{
throw new UnsupportedOperationException(format("not yet implemented: %s.visit%s", getClass().getName(), node.getClass().getSimpleName()));
}
@Override
protected String visitPatternAlternation(PatternAlternation node, Void context)
{
return node.getPatterns().stream()
.map(child -> process(child, context))
.collect(joining(" | ", "(", ")"));
}
@Override
protected String visitPatternConcatenation(PatternConcatenation node, Void context)
{
return node.getPatterns().stream()
.map(child -> process(child, context))
.collect(joining(" ", "(", ")"));
}
@Override
protected String visitQuantifiedPattern(QuantifiedPattern node, Void context)
{
return "(" + process(node.getPattern(), context) + process(node.getPatternQuantifier(), context) + ")";
}
@Override
protected String visitPatternVariable(PatternVariable node, Void context)
{
return formatExpression(node.getName(), dialect);
}
@Override
protected String visitEmptyPattern(EmptyPattern node, Void context)
{
return "()";
}
@Override
protected String visitPatternPermutation(PatternPermutation node, Void context)
{
return node.getPatterns().stream()
.map(child -> process(child, context))
.collect(joining(", ", "PERMUTE(", ")"));
}
@Override
protected String visitAnchorPattern(AnchorPattern node, Void context)
{
switch (node.getType()) {
case PARTITION_START:
return "^";
case PARTITION_END:
return "$";
default:
throw new IllegalStateException("unexpected anchor pattern type: " + node.getType());
}
}
@Override
protected String visitExcludedPattern(ExcludedPattern node, Void context)
{
return "{-" + process(node.getPattern(), context) + "-}";
}
@Override
protected String visitZeroOrMoreQuantifier(ZeroOrMoreQuantifier node, Void context)
{
String greedy = node.isGreedy() ? "" : "?";
return "*" + greedy;
}
@Override
protected String visitOneOrMoreQuantifier(OneOrMoreQuantifier node, Void context)
{
String greedy = node.isGreedy() ? "" : "?";
return "+" + greedy;
}
@Override
protected String visitZeroOrOneQuantifier(ZeroOrOneQuantifier node, Void context)
{
String greedy = node.isGreedy() ? "" : "?";
return "?" + greedy;
}
@Override
protected String visitRangeQuantifier(RangeQuantifier node, Void context)
{
String greedy = node.isGreedy() ? "" : "?";
String atLeast = node.getAtLeast().map(expression -> formatExpression(expression, dialect)).orElse("");
String atMost = node.getAtMost().map(expression -> formatExpression(expression, dialect)).orElse("");
return "{" + atLeast + "," + atMost + "}" + greedy;
}
}
}
File diff suppressed because it is too large Load Diff
@@ -1,462 +0,0 @@
package io.trino.sql;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import io.trino.sql.tree.AliasedRelation;
import io.trino.sql.tree.AllColumns;
import io.trino.sql.tree.ArithmeticBinaryExpression;
import io.trino.sql.tree.AstVisitor;
import io.trino.sql.tree.BinaryLiteral;
import io.trino.sql.tree.BooleanLiteral;
import io.trino.sql.tree.ComparisonExpression;
import io.trino.sql.tree.Cube;
import io.trino.sql.tree.DefaultTraversalVisitor;
import io.trino.sql.tree.DereferenceExpression;
import io.trino.sql.tree.Expression;
import io.trino.sql.tree.FunctionCall;
import io.trino.sql.tree.GroupingElement;
import io.trino.sql.tree.GroupingSets;
import io.trino.sql.tree.Identifier;
import io.trino.sql.tree.InPredicate;
import io.trino.sql.tree.LikePredicate;
import io.trino.sql.tree.LogicalExpression;
import io.trino.sql.tree.LongLiteral;
import io.trino.sql.tree.Node;
import io.trino.sql.tree.OrderBy;
import io.trino.sql.tree.QualifiedName;
import io.trino.sql.tree.Query;
import io.trino.sql.tree.QuerySpecification;
import io.trino.sql.tree.Rollup;
import io.trino.sql.tree.Row;
import io.trino.sql.tree.SampledRelation;
import io.trino.sql.tree.Select;
import io.trino.sql.tree.SimpleGroupBy;
import io.trino.sql.tree.SingleColumn;
import io.trino.sql.tree.SortItem;
import io.trino.sql.tree.StringLiteral;
import io.trino.sql.tree.SubqueryExpression;
import io.trino.sql.tree.Table;
import io.trino.sql.tree.TableSubquery;
import io.trino.sql.tree.Values;
import io.trino.sql.tree.WindowDefinition;
import io.trino.sql.tree.WindowReference;
import io.trino.sql.tree.WindowSpecification;
import java.io.PrintStream;
import java.util.IdentityHashMap;
import java.util.List;
public class TreePrinter
{
private static final String INDENT = " ";
private final IdentityHashMap<Expression, QualifiedName> resolvedNameReferences;
private final PrintStream out;
public TreePrinter(IdentityHashMap<Expression, QualifiedName> resolvedNameReferences, PrintStream out)
{
this.resolvedNameReferences = new IdentityHashMap<>(resolvedNameReferences);
this.out = out;
}
public void print(Node root)
{
AstVisitor<Void, Integer> printer = new DefaultTraversalVisitor<Integer>()
{
@Override
protected Void visitNode(Node node, Integer indentLevel)
{
throw new UnsupportedOperationException("not yet implemented: " + node);
}
@Override
protected Void visitQuery(Query node, Integer indentLevel)
{
print(indentLevel, "Query ");
indentLevel++;
print(indentLevel, "QueryBody");
process(node.getQueryBody(), indentLevel);
if (node.getOrderBy().isPresent()) {
print(indentLevel, "OrderBy");
process(node.getOrderBy().get(), indentLevel + 1);
}
if (node.getLimit().isPresent()) {
print(indentLevel, "Limit: " + node.getLimit().get());
}
return null;
}
@Override
protected Void visitQuerySpecification(QuerySpecification node, Integer indentLevel)
{
print(indentLevel, "QuerySpecification ");
indentLevel++;
process(node.getSelect(), indentLevel);
if (node.getFrom().isPresent()) {
print(indentLevel, "From");
process(node.getFrom().get(), indentLevel + 1);
}
if (node.getWhere().isPresent()) {
print(indentLevel, "Where");
process(node.getWhere().get(), indentLevel + 1);
}
if (node.getGroupBy().isPresent()) {
String distinct = "";
if (node.getGroupBy().get().isDistinct()) {
distinct = "[DISTINCT]";
}
print(indentLevel, "GroupBy" + distinct);
for (GroupingElement groupingElement : node.getGroupBy().get().getGroupingElements()) {
print(indentLevel, "SimpleGroupBy");
if (groupingElement instanceof SimpleGroupBy) {
for (Expression column : groupingElement.getExpressions()) {
process(column, indentLevel + 1);
}
}
else if (groupingElement instanceof GroupingSets) {
print(indentLevel + 1, "GroupingSets");
for (List<Expression> set : ((GroupingSets) groupingElement).getSets()) {
print(indentLevel + 2, "GroupingSet[");
for (Expression expression : set) {
process(expression, indentLevel + 3);
}
print(indentLevel + 2, "]");
}
}
else if (groupingElement instanceof Cube) {
print(indentLevel + 1, "Cube");
for (Expression column : groupingElement.getExpressions()) {
process(column, indentLevel + 1);
}
}
else if (groupingElement instanceof Rollup) {
print(indentLevel + 1, "Rollup");
for (Expression column : groupingElement.getExpressions()) {
process(column, indentLevel + 1);
}
}
}
}
if (node.getHaving().isPresent()) {
print(indentLevel, "Having");
process(node.getHaving().get(), indentLevel + 1);
}
if (!node.getWindows().isEmpty()) {
print(indentLevel, "Window");
for (WindowDefinition windowDefinition : node.getWindows()) {
process(windowDefinition, indentLevel + 1);
}
}
if (node.getOrderBy().isPresent()) {
print(indentLevel, "OrderBy");
process(node.getOrderBy().get(), indentLevel + 1);
}
if (node.getLimit().isPresent()) {
print(indentLevel, "Limit: " + node.getLimit().get());
}
return null;
}
@Override
protected Void visitOrderBy(OrderBy node, Integer indentLevel)
{
for (SortItem sortItem : node.getSortItems()) {
process(sortItem, indentLevel);
}
return null;
}
@Override
protected Void visitWindowDefinition(WindowDefinition node, Integer indentLevel)
{
print(indentLevel, "WindowDefinition[" + node.getName() + "]");
process(node.getWindow(), indentLevel + 1);
return null;
}
@Override
protected Void visitWindowReference(WindowReference node, Integer indentLevel)
{
print(indentLevel, "WindowReference[" + node.getName() + "]");
return null;
}
@Override
public Void visitWindowSpecification(WindowSpecification node, Integer indentLevel)
{
if (node.getExistingWindowName().isPresent()) {
print(indentLevel, "ExistingWindowName " + node.getExistingWindowName().get());
}
if (!node.getPartitionBy().isEmpty()) {
print(indentLevel, "PartitionBy");
for (Expression expression : node.getPartitionBy()) {
process(expression, indentLevel + 1);
}
}
if (node.getOrderBy().isPresent()) {
print(indentLevel, "OrderBy");
process(node.getOrderBy().get(), indentLevel + 1);
}
if (node.getFrame().isPresent()) {
print(indentLevel, "Frame");
process(node.getFrame().get(), indentLevel + 1);
}
return null;
}
@Override
protected Void visitSelect(Select node, Integer indentLevel)
{
String distinct = "";
if (node.isDistinct()) {
distinct = "[DISTINCT]";
}
print(indentLevel, "Select" + distinct);
super.visitSelect(node, indentLevel + 1); // visit children
return null;
}
@Override
protected Void visitAllColumns(AllColumns node, Integer indent)
{
StringBuilder aliases = new StringBuilder();
if (!node.getAliases().isEmpty()) {
aliases.append(" [Aliases: ");
Joiner.on(", ").appendTo(aliases, node.getAliases());
aliases.append("]");
}
print(indent, "All columns" + aliases.toString());
if (node.getTarget().isPresent()) {
super.visitAllColumns(node, indent + 1); // visit child
}
return null;
}
@Override
protected Void visitSingleColumn(SingleColumn node, Integer indent)
{
if (node.getAlias().isPresent()) {
print(indent, "Alias: " + node.getAlias().get());
}
super.visitSingleColumn(node, indent + 1); // visit children
return null;
}
@Override
protected Void visitComparisonExpression(ComparisonExpression node, Integer indentLevel)
{
print(indentLevel, node.getOperator().toString());
super.visitComparisonExpression(node, indentLevel + 1);
return null;
}
@Override
protected Void visitArithmeticBinary(ArithmeticBinaryExpression node, Integer indentLevel)
{
print(indentLevel, node.getOperator().toString());
super.visitArithmeticBinary(node, indentLevel + 1);
return null;
}
@Override
protected Void visitLogicalExpression(LogicalExpression node, Integer indentLevel)
{
print(indentLevel, node.getOperator().toString());
super.visitLogicalExpression(node, indentLevel + 1);
return null;
}
@Override
protected Void visitStringLiteral(StringLiteral node, Integer indentLevel)
{
print(indentLevel, "String[" + node.getValue() + "]");
return null;
}
@Override
protected Void visitBinaryLiteral(BinaryLiteral node, Integer indentLevel)
{
print(indentLevel, "Binary[" + node.toHexString() + "]");
return null;
}
@Override
protected Void visitBooleanLiteral(BooleanLiteral node, Integer indentLevel)
{
print(indentLevel, "Boolean[" + node.getValue() + "]");
return null;
}
@Override
protected Void visitLongLiteral(LongLiteral node, Integer indentLevel)
{
print(indentLevel, "Long[" + node.getValue() + "]");
return null;
}
@Override
protected Void visitLikePredicate(LikePredicate node, Integer indentLevel)
{
print(indentLevel, "LIKE");
super.visitLikePredicate(node, indentLevel + 1);
return null;
}
@Override
protected Void visitIdentifier(Identifier node, Integer indentLevel)
{
QualifiedName resolved = resolvedNameReferences.get(node);
String resolvedName = "";
if (resolved != null) {
resolvedName = "=>" + resolved.toString();
}
print(indentLevel, "Identifier[" + node.getValue() + resolvedName + "]");
return null;
}
@Override
protected Void visitDereferenceExpression(DereferenceExpression node, Integer indentLevel)
{
QualifiedName resolved = resolvedNameReferences.get(node);
String resolvedName = "";
if (resolved != null) {
resolvedName = "=>" + resolved.toString();
}
print(indentLevel, "DereferenceExpression[" + node + resolvedName + "]");
return null;
}
@Override
protected Void visitFunctionCall(FunctionCall node, Integer indentLevel)
{
String name = Joiner.on('.').join(node.getName().getParts());
print(indentLevel, "FunctionCall[" + name + "]");
super.visitFunctionCall(node, indentLevel + 1);
return null;
}
@Override
protected Void visitTable(Table node, Integer indentLevel)
{
String name = Joiner.on('.').join(node.getName().getParts());
print(indentLevel, "Table[" + name + "]");
return null;
}
@Override
protected Void visitValues(Values node, Integer indentLevel)
{
print(indentLevel, "Values");
super.visitValues(node, indentLevel + 1);
return null;
}
@Override
protected Void visitRow(Row node, Integer indentLevel)
{
print(indentLevel, "Row");
super.visitRow(node, indentLevel + 1);
return null;
}
@Override
protected Void visitAliasedRelation(AliasedRelation node, Integer indentLevel)
{
print(indentLevel, "Alias[" + node.getAlias() + "]");
super.visitAliasedRelation(node, indentLevel + 1);
return null;
}
@Override
protected Void visitSampledRelation(SampledRelation node, Integer indentLevel)
{
print(indentLevel, "TABLESAMPLE[" + node.getType() + " (" + node.getSamplePercentage() + ")]");
super.visitSampledRelation(node, indentLevel + 1);
return null;
}
@Override
protected Void visitTableSubquery(TableSubquery node, Integer indentLevel)
{
print(indentLevel, "SubQuery");
super.visitTableSubquery(node, indentLevel + 1);
return null;
}
@Override
protected Void visitInPredicate(InPredicate node, Integer indentLevel)
{
print(indentLevel, "IN");
super.visitInPredicate(node, indentLevel + 1);
return null;
}
@Override
protected Void visitSubqueryExpression(SubqueryExpression node, Integer indentLevel)
{
print(indentLevel, "SubQuery");
super.visitSubqueryExpression(node, indentLevel + 1);
return null;
}
};
printer.process(root, 0);
}
private void print(Integer indentLevel, String value)
{
out.println(Strings.repeat(INDENT, indentLevel) + value);
}
}
@@ -1,66 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.parser;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.ParserATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.dfa.DFA;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
public final class AntlrATNCacheFields
{
private final ATN atn;
private final PredictionContextCache predictionContextCache;
private final DFA[] decisionToDFA;
public AntlrATNCacheFields(ATN atn)
{
this.atn = requireNonNull(atn, "atn is null");
this.predictionContextCache = new PredictionContextCache();
this.decisionToDFA = createDecisionToDFA(atn);
}
@SuppressWarnings("ObjectEquality")
public void configureLexer(Lexer lexer)
{
requireNonNull(lexer, "lexer is null");
// Intentional identity equals comparison
checkArgument(atn == lexer.getATN(), "Lexer ATN mismatch: expected %s, found %s", atn, lexer.getATN());
lexer.setInterpreter(new LexerATNSimulator(lexer, atn, decisionToDFA, predictionContextCache));
}
@SuppressWarnings("ObjectEquality")
public void configureParser(Parser parser)
{
requireNonNull(parser, "parser is null");
// Intentional identity equals comparison
checkArgument(atn == parser.getATN(), "Parser ATN mismatch: expected %s, found %s", atn, parser.getATN());
parser.setInterpreter(new ParserATNSimulator(parser, atn, decisionToDFA, predictionContextCache));
}
private static DFA[] createDecisionToDFA(ATN atn)
{
DFA[] decisionToDFA = new DFA[atn.getNumberOfDecisions()];
for (int i = 0; i < decisionToDFA.length; i++) {
decisionToDFA[i] = new DFA(atn.getDecisionState(i), i);
}
return decisionToDFA;
}
}
File diff suppressed because it is too large Load Diff
@@ -1,91 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.parser;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.IntStream;
import org.antlr.v4.runtime.misc.Interval;
public class CaseInsensitiveStream
implements CharStream
{
private final CharStream stream;
public CaseInsensitiveStream(CharStream stream)
{
this.stream = stream;
}
@Override
public String getText(Interval interval)
{
return stream.getText(interval);
}
@Override
public void consume()
{
stream.consume();
}
@Override
public int LA(int i)
{
int result = stream.LA(i);
switch (result) {
case 0:
case IntStream.EOF:
return result;
default:
return Character.toUpperCase(result);
}
}
@Override
public int mark()
{
return stream.mark();
}
@Override
public void release(int marker)
{
stream.release(marker);
}
@Override
public int index()
{
return stream.index();
}
@Override
public void seek(int index)
{
stream.seek(index);
}
@Override
public int size()
{
return stream.size();
}
@Override
public String getSourceName()
{
return stream.getSourceName();
}
}
@@ -1,126 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.parser;
import com.google.common.collect.ImmutableSet;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.IntStream;
import org.antlr.v4.runtime.LexerNoViableAltException;
import org.antlr.v4.runtime.Token;
import java.util.Set;
/**
* This is a special-purpose lexer that can identify custom delimiters in addition to every other
* token in the SQL grammar.
* <p>
* The code in nextToken() is a copy of the implementation in org.antlr.v4.runtime.Lexer, with a
* bit added to match the token before the default behavior is invoked.
*/
class DelimiterLexer
extends SqlBaseLexer
{
private final Set<String> delimiters;
public DelimiterLexer(CharStream input, Set<String> delimiters)
{
super(input);
this.delimiters = ImmutableSet.copyOf(delimiters);
}
@Override
public Token nextToken()
{
if (_input == null) {
throw new IllegalStateException("nextToken requires a non-null input stream.");
}
// Mark start location in char stream so unbuffered streams are
// guaranteed at least have text of current token
int tokenStartMarker = _input.mark();
try {
outer:
while (true) {
if (_hitEOF) {
emitEOF();
return _token;
}
_token = null;
_channel = Token.DEFAULT_CHANNEL;
_tokenStartCharIndex = _input.index();
_tokenStartCharPositionInLine = getInterpreter().getCharPositionInLine();
_tokenStartLine = getInterpreter().getLine();
_text = null;
do {
_type = Token.INVALID_TYPE;
int ttype = -1;
// This entire method is copied from org.antlr.v4.runtime.Lexer, with the following bit
// added to match the delimiters before we attempt to match the token
boolean found = false;
for (String terminator : delimiters) {
if (match(terminator)) {
ttype = SqlBaseParser.DELIMITER;
found = true;
break;
}
}
if (!found) {
try {
ttype = getInterpreter().match(_input, _mode);
}
catch (LexerNoViableAltException e) {
notifyListeners(e); // report error
recover(e);
ttype = SKIP;
}
}
if (_input.LA(1) == IntStream.EOF) {
_hitEOF = true;
}
if (_type == Token.INVALID_TYPE) {
_type = ttype;
}
if (_type == SKIP) {
continue outer;
}
}
while (_type == MORE);
if (_token == null) {
emit();
}
return _token;
}
}
finally {
// make sure we release marker after match or
// unbuffered char stream will keep buffering
_input.release(tokenStartMarker);
}
}
private boolean match(String delimiter)
{
for (int i = 0; i < delimiter.length(); i++) {
if (_input.LA(i + 1) != delimiter.charAt(i)) {
return false;
}
}
_input.seek(_input.index() + delimiter.length());
return true;
}
}
@@ -1,436 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.parser;
import com.google.common.collect.ImmutableSet;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.RuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.Vocabulary;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNState;
import org.antlr.v4.runtime.atn.NotSetTransition;
import org.antlr.v4.runtime.atn.PrecedencePredicateTransition;
import org.antlr.v4.runtime.atn.RuleStartState;
import org.antlr.v4.runtime.atn.RuleStopState;
import org.antlr.v4.runtime.atn.RuleTransition;
import org.antlr.v4.runtime.atn.Transition;
import org.antlr.v4.runtime.atn.WildcardTransition;
import org.antlr.v4.runtime.misc.IntervalSet;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import static com.google.common.base.MoreObjects.firstNonNull;
import static java.lang.String.format;
import static java.util.logging.Level.SEVERE;
import static org.antlr.v4.runtime.atn.ATNState.RULE_START;
class ErrorHandler
extends BaseErrorListener
{
private static final Logger LOG = Logger.getLogger(ErrorHandler.class.getName());
private final Map<Integer, String> specialRules;
private final Map<Integer, String> specialTokens;
private final Set<Integer> ignoredRules;
private ErrorHandler(Map<Integer, String> specialRules, Map<Integer, String> specialTokens, Set<Integer> ignoredRules)
{
this.specialRules = new HashMap<>(specialRules);
this.specialTokens = specialTokens;
this.ignoredRules = new HashSet<>(ignoredRules);
}
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String message, RecognitionException e)
{
try {
Parser parser = (Parser) recognizer;
ATN atn = parser.getATN();
ATNState currentState;
Token currentToken;
RuleContext context;
if (e != null) {
currentState = atn.states.get(e.getOffendingState());
currentToken = e.getOffendingToken();
context = e.getCtx();
if (e instanceof NoViableAltException) {
currentToken = ((NoViableAltException) e).getStartToken();
}
}
else {
currentState = atn.states.get(parser.getState());
currentToken = parser.getCurrentToken();
context = parser.getContext();
}
Analyzer analyzer = new Analyzer(parser, specialRules, specialTokens, ignoredRules);
Result result = analyzer.process(currentState, currentToken.getTokenIndex(), context);
// pick the candidate tokens associated largest token index processed (i.e., the path that consumed the most input)
String expected = result.getExpected().stream()
.sorted()
.collect(Collectors.joining(", "));
message = format("mismatched input '%s'. Expecting: %s", parser.getTokenStream().get(result.getErrorTokenIndex()).getText(), expected);
}
catch (Exception exception) {
LOG.log(SEVERE, "Unexpected failure when handling parsing error. This is likely a bug in the implementation", exception);
}
throw new ParsingException(message, e, line, charPositionInLine + 1);
}
private static class ParsingState
{
public final ATNState state;
public final int tokenIndex;
public final boolean suppressed;
public final Parser parser;
public ParsingState(ATNState state, int tokenIndex, boolean suppressed, Parser parser)
{
this.state = state;
this.tokenIndex = tokenIndex;
this.suppressed = suppressed;
this.parser = parser;
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ParsingState that = (ParsingState) o;
return tokenIndex == that.tokenIndex &&
state.equals(that.state);
}
@Override
public int hashCode()
{
return Objects.hash(state, tokenIndex);
}
@Override
public String toString()
{
Token token = parser.getTokenStream().get(tokenIndex);
String text = firstNonNull(token.getText(), "?");
if (text != null) {
text = text.replace("\\", "\\\\");
text = text.replace("\n", "\\n");
text = text.replace("\r", "\\r");
text = text.replace("\t", "\\t");
}
return format(
"%s%s:%s @ %s:<%s>:%s",
suppressed ? "-" : "+",
parser.getRuleNames()[state.ruleIndex],
state.stateNumber,
tokenIndex,
parser.getVocabulary().getSymbolicName(token.getType()),
text);
}
}
private static class Analyzer
{
private final Parser parser;
private final ATN atn;
private final Vocabulary vocabulary;
private final Map<Integer, String> specialRules;
private final Map<Integer, String> specialTokens;
private final Set<Integer> ignoredRules;
private final TokenStream stream;
private int furthestTokenIndex = -1;
private final Set<String> candidates = new HashSet<>();
private final Map<ParsingState, Set<Integer>> memo = new HashMap<>();
public Analyzer(
Parser parser,
Map<Integer, String> specialRules,
Map<Integer, String> specialTokens,
Set<Integer> ignoredRules)
{
this.parser = parser;
this.stream = parser.getTokenStream();
this.atn = parser.getATN();
this.vocabulary = parser.getVocabulary();
this.specialRules = specialRules;
this.specialTokens = specialTokens;
this.ignoredRules = ignoredRules;
}
public Result process(ATNState currentState, int tokenIndex, RuleContext context)
{
RuleStartState startState = atn.ruleToStartState[currentState.ruleIndex];
if (isReachable(currentState, startState)) {
// We've been dropped inside a rule in a state that's reachable via epsilon transitions. This is,
// effectively, equivalent to starting at the beginning (or immediately outside) the rule.
// In that case, backtrack to the beginning to be able to take advantage of logic that remaps
// some rules to well-known names for reporting purposes
currentState = startState;
}
Set<Integer> endTokens = process(new ParsingState(currentState, tokenIndex, false, parser), 0);
Set<Integer> nextTokens = new HashSet<>();
while (!endTokens.isEmpty() && context.invokingState != -1) {
for (int endToken : endTokens) {
ATNState nextState = ((RuleTransition) atn.states.get(context.invokingState).transition(0)).followState;
nextTokens.addAll(process(new ParsingState(nextState, endToken, false, parser), 0));
}
context = context.parent;
endTokens = nextTokens;
}
return new Result(furthestTokenIndex, candidates);
}
private boolean isReachable(ATNState target, RuleStartState from)
{
Deque<ATNState> activeStates = new ArrayDeque<>();
activeStates.add(from);
while (!activeStates.isEmpty()) {
ATNState current = activeStates.pop();
if (current.stateNumber == target.stateNumber) {
return true;
}
for (int i = 0; i < current.getNumberOfTransitions(); i++) {
Transition transition = current.transition(i);
if (transition.isEpsilon()) {
activeStates.push(transition.target);
}
}
}
return false;
}
private Set<Integer> process(ParsingState start, int precedence)
{
Set<Integer> result = memo.get(start);
if (result != null) {
return result;
}
ImmutableSet.Builder<Integer> endTokens = ImmutableSet.builder();
// Simulates the ATN by consuming input tokens and walking transitions.
// The ATN can be in multiple states (similar to an NFA)
Deque<ParsingState> activeStates = new ArrayDeque<>();
activeStates.add(start);
while (!activeStates.isEmpty()) {
ParsingState current = activeStates.pop();
ATNState state = current.state;
int tokenIndex = current.tokenIndex;
boolean suppressed = current.suppressed;
while (stream.get(tokenIndex).getChannel() == Token.HIDDEN_CHANNEL) {
// Ignore whitespace
tokenIndex++;
}
int currentToken = stream.get(tokenIndex).getType();
if (state.getStateType() == RULE_START) {
int rule = state.ruleIndex;
if (specialRules.containsKey(rule)) {
if (!suppressed) {
record(tokenIndex, specialRules.get(rule));
}
suppressed = true;
}
else if (ignoredRules.contains(rule)) {
// TODO expand ignored rules like we expand special rules
continue;
}
}
if (state instanceof RuleStopState) {
endTokens.add(tokenIndex);
continue;
}
for (int i = 0; i < state.getNumberOfTransitions(); i++) {
Transition transition = state.transition(i);
if (transition instanceof RuleTransition) {
RuleTransition ruleTransition = (RuleTransition) transition;
for (int endToken : process(new ParsingState(ruleTransition.target, tokenIndex, suppressed, parser), ruleTransition.precedence)) {
activeStates.push(new ParsingState(ruleTransition.followState, endToken, suppressed, parser));
}
}
else if (transition instanceof PrecedencePredicateTransition) {
if (precedence < ((PrecedencePredicateTransition) transition).precedence) {
activeStates.push(new ParsingState(transition.target, tokenIndex, suppressed, parser));
}
}
else if (transition.isEpsilon()) {
activeStates.push(new ParsingState(transition.target, tokenIndex, suppressed, parser));
}
else if (transition instanceof WildcardTransition) {
throw new UnsupportedOperationException("not yet implemented: wildcard transition");
}
else {
IntervalSet labels = transition.label();
if (transition instanceof NotSetTransition) {
labels = labels.complement(IntervalSet.of(Token.MIN_USER_TOKEN_TYPE, atn.maxTokenType));
}
// Surprisingly, TokenStream (i.e. BufferedTokenStream) may not have loaded all the tokens from the
// underlying stream. TokenStream.get() does not force tokens to be buffered -- it just returns what's
// in the current buffer, or fail with an IndexOutOfBoundsError. Since Antlr decided the error occurred
// within the current set of buffered tokens, stop when we reach the end of the buffer.
if (labels.contains(currentToken) && tokenIndex < stream.size() - 1) {
activeStates.push(new ParsingState(transition.target, tokenIndex + 1, false, parser));
}
else {
if (!suppressed) {
record(tokenIndex, getTokenNames(labels));
}
}
}
}
}
result = endTokens.build();
memo.put(start, result);
return result;
}
private void record(int tokenIndex, String label)
{
record(tokenIndex, ImmutableSet.of(label));
}
private void record(int tokenIndex, Set<String> labels)
{
if (tokenIndex >= furthestTokenIndex) {
if (tokenIndex > furthestTokenIndex) {
candidates.clear();
furthestTokenIndex = tokenIndex;
}
candidates.addAll(labels);
}
}
private Set<String> getTokenNames(IntervalSet tokens)
{
Set<String> names = new HashSet<>();
for (int i = 0; i < tokens.size(); i++) {
int token = tokens.get(i);
if (token == Token.EOF) {
names.add("<EOF>");
}
else {
names.add(specialTokens.getOrDefault(token, vocabulary.getDisplayName(token)));
}
}
return names;
}
}
public static Builder builder()
{
return new Builder();
}
public static class Builder
{
private final Map<Integer, String> specialRules = new HashMap<>();
private final Map<Integer, String> specialTokens = new HashMap<>();
private final Set<Integer> ignoredRules = new HashSet<>();
public Builder specialRule(int ruleId, String name)
{
specialRules.put(ruleId, name);
return this;
}
public Builder specialToken(int tokenId, String name)
{
specialTokens.put(tokenId, name);
return this;
}
public Builder ignoredRule(int ruleId)
{
ignoredRules.add(ruleId);
return this;
}
public ErrorHandler build()
{
return new ErrorHandler(specialRules, specialTokens, ignoredRules);
}
}
private static class Result
{
private final int errorTokenIndex;
private final Set<String> expected;
public Result(int errorTokenIndex, Set<String> expected)
{
this.errorTokenIndex = errorTokenIndex;
this.expected = expected;
}
public int getErrorTokenIndex()
{
return errorTokenIndex;
}
public Set<String> getExpected()
{
return expected;
}
}
}
@@ -1,68 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.parser;
import io.trino.sql.tree.NodeLocation;
import org.antlr.v4.runtime.RecognitionException;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
public class ParsingException
extends RuntimeException
{
private final int line;
private final int column;
public ParsingException(String message, RecognitionException cause, int line, int column)
{
super(message, cause);
checkArgument(line > 0, "line must be > 0");
checkArgument(column > 0, "column must be > 0");
this.line = line;
this.column = column;
}
public ParsingException(String message)
{
this(message, null, 1, 1);
}
public ParsingException(String message, NodeLocation nodeLocation)
{
this(message, null, nodeLocation.getLineNumber(), nodeLocation.getColumnNumber());
}
public int getLineNumber()
{
return line;
}
public int getColumnNumber()
{
return column;
}
public String getErrorMessage()
{
return super.getMessage();
}
@Override
public String getMessage()
{
return format("line %s:%s: %s", getLineNumber(), getColumnNumber(), getErrorMessage());
}
}
@@ -1,43 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.parser;
import static java.util.Objects.requireNonNull;
public class ParsingOptions
{
public enum DecimalLiteralTreatment
{
AS_DOUBLE,
AS_DECIMAL,
REJECT
}
private final DecimalLiteralTreatment decimalLiteralTreatment;
public ParsingOptions()
{
this(DecimalLiteralTreatment.REJECT);
}
public ParsingOptions(DecimalLiteralTreatment decimalLiteralTreatment)
{
this.decimalLiteralTreatment = requireNonNull(decimalLiteralTreatment, "decimalLiteralTreatment is null");
}
public DecimalLiteralTreatment getDecimalLiteralTreatment()
{
return decimalLiteralTreatment;
}
}
@@ -1,50 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.parser;
import javax.annotation.concurrent.ThreadSafe;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
@ThreadSafe
public final class RefreshableSqlBaseParserInitializer
implements BiConsumer<SqlBaseLexer, SqlBaseParser>
{
private final AtomicReference<SqlBaseParserAndLexerATNCaches> caches = new AtomicReference<>();
public RefreshableSqlBaseParserInitializer()
{
refresh();
}
public void refresh()
{
caches.set(new SqlBaseParserAndLexerATNCaches());
}
@Override
public void accept(SqlBaseLexer lexer, SqlBaseParser parser)
{
SqlBaseParserAndLexerATNCaches caches = this.caches.get();
caches.lexer.configureLexer(lexer);
caches.parser.configureParser(parser);
}
private static final class SqlBaseParserAndLexerATNCaches
{
public final AntlrATNCacheFields lexer = new AntlrATNCacheFields(SqlBaseLexer._ATN);
public final AntlrATNCacheFields parser = new AntlrATNCacheFields(SqlBaseParser._ATN);
}
}
@@ -1,230 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.parser;
import io.trino.sql.tree.DataType;
import io.trino.sql.tree.Expression;
import io.trino.sql.tree.Node;
import io.trino.sql.tree.PathSpecification;
import io.trino.sql.tree.RowPattern;
import io.trino.sql.tree.Statement;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonToken;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.DefaultErrorStrategy;
import org.antlr.v4.runtime.InputMismatchException;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.misc.Pair;
import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.antlr.v4.runtime.tree.TerminalNode;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;
import static java.util.Objects.requireNonNull;
public class SqlParser
{
private static final BaseErrorListener LEXER_ERROR_LISTENER = new BaseErrorListener()
{
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String message, RecognitionException e)
{
throw new ParsingException(message, e, line, charPositionInLine + 1);
}
};
private static final BiConsumer<SqlBaseLexer, SqlBaseParser> DEFAULT_PARSER_INITIALIZER = (SqlBaseLexer lexer, SqlBaseParser parser) -> {};
private static final ErrorHandler PARSER_ERROR_HANDLER = ErrorHandler.builder()
.specialRule(SqlBaseParser.RULE_expression, "<expression>")
.specialRule(SqlBaseParser.RULE_booleanExpression, "<expression>")
.specialRule(SqlBaseParser.RULE_valueExpression, "<expression>")
.specialRule(SqlBaseParser.RULE_primaryExpression, "<expression>")
.specialRule(SqlBaseParser.RULE_predicate, "<predicate>")
.specialRule(SqlBaseParser.RULE_identifier, "<identifier>")
.specialRule(SqlBaseParser.RULE_string, "<string>")
.specialRule(SqlBaseParser.RULE_query, "<query>")
.specialRule(SqlBaseParser.RULE_type, "<type>")
.specialToken(SqlBaseLexer.INTEGER_VALUE, "<integer>")
.ignoredRule(SqlBaseParser.RULE_nonReserved)
.build();
private final BiConsumer<SqlBaseLexer, SqlBaseParser> initializer;
public SqlParser()
{
this(DEFAULT_PARSER_INITIALIZER);
}
public SqlParser(BiConsumer<SqlBaseLexer, SqlBaseParser> initializer)
{
this.initializer = requireNonNull(initializer, "initializer is null");
}
public Statement createStatement(String sql, ParsingOptions parsingOptions)
{
return (Statement) invokeParser("statement", sql, SqlBaseParser::singleStatement, parsingOptions);
}
public Expression createExpression(String expression, ParsingOptions parsingOptions)
{
return (Expression) invokeParser("expression", expression, SqlBaseParser::standaloneExpression, parsingOptions);
}
public DataType createType(String expression)
{
return (DataType) invokeParser("type", expression, SqlBaseParser::standaloneType, new ParsingOptions());
}
public PathSpecification createPathSpecification(String expression)
{
return (PathSpecification) invokeParser("path specification", expression, SqlBaseParser::standalonePathSpecification, new ParsingOptions());
}
public RowPattern createRowPattern(String pattern)
{
return (RowPattern) invokeParser("row pattern", pattern, SqlBaseParser::standaloneRowPattern, new ParsingOptions());
}
private Node invokeParser(String name, String sql, Function<SqlBaseParser, ParserRuleContext> parseFunction, ParsingOptions parsingOptions)
{
try {
SqlBaseLexer lexer = new SqlBaseLexer(new CaseInsensitiveStream(CharStreams.fromString(sql)));
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
SqlBaseParser parser = new SqlBaseParser(tokenStream);
initializer.accept(lexer, parser);
// Override the default error strategy to not attempt inserting or deleting a token.
// Otherwise, it messes up error reporting
parser.setErrorHandler(new DefaultErrorStrategy()
{
@Override
public Token recoverInline(Parser recognizer)
throws RecognitionException
{
if (nextTokensContext == null) {
throw new InputMismatchException(recognizer);
}
else {
throw new InputMismatchException(recognizer, nextTokensState, nextTokensContext);
}
}
});
parser.addParseListener(new PostProcessor(Arrays.asList(parser.getRuleNames()), parser));
lexer.removeErrorListeners();
lexer.addErrorListener(LEXER_ERROR_LISTENER);
parser.removeErrorListeners();
parser.addErrorListener(PARSER_ERROR_HANDLER);
ParserRuleContext tree;
try {
// first, try parsing with potentially faster SLL mode
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
tree = parseFunction.apply(parser);
}
catch (ParseCancellationException ex) {
// if we fail, parse with LL mode
tokenStream.seek(0); // rewind input stream
parser.reset();
parser.getInterpreter().setPredictionMode(PredictionMode.LL);
tree = parseFunction.apply(parser);
}
return new AstBuilder(parsingOptions).visit(tree);
}
catch (StackOverflowError e) {
throw new ParsingException(name + " is too large (stack overflow while parsing)");
}
}
private static class PostProcessor
extends SqlBaseBaseListener
{
private final List<String> ruleNames;
private final SqlBaseParser parser;
public PostProcessor(List<String> ruleNames, SqlBaseParser parser)
{
this.ruleNames = ruleNames;
this.parser = parser;
}
@Override
public void exitQuotedIdentifier(SqlBaseParser.QuotedIdentifierContext context)
{
Token token = context.QUOTED_IDENTIFIER().getSymbol();
if (token.getText().length() == 2) { // empty identifier
throw new ParsingException("Zero-length delimited identifier not allowed", null, token.getLine(), token.getCharPositionInLine() + 1);
}
}
@Override
public void exitBackQuotedIdentifier(SqlBaseParser.BackQuotedIdentifierContext context)
{
Token token = context.BACKQUOTED_IDENTIFIER().getSymbol();
throw new ParsingException(
"backquoted identifiers are not supported; use double quotes to quote identifiers",
null,
token.getLine(),
token.getCharPositionInLine() + 1);
}
@Override
public void exitDigitIdentifier(SqlBaseParser.DigitIdentifierContext context)
{
Token token = context.DIGIT_IDENTIFIER().getSymbol();
throw new ParsingException(
"identifiers must not start with a digit; surround the identifier with double quotes",
null,
token.getLine(),
token.getCharPositionInLine() + 1);
}
@Override
public void exitNonReserved(SqlBaseParser.NonReservedContext context)
{
// we can't modify the tree during rule enter/exit event handling unless we're dealing with a terminal.
// Otherwise, ANTLR gets confused and fires spurious notifications.
if (!(context.getChild(0) instanceof TerminalNode)) {
int rule = ((ParserRuleContext) context.getChild(0)).getRuleIndex();
throw new AssertionError("nonReserved can only contain tokens. Found nested rule: " + ruleNames.get(rule));
}
// replace nonReserved words with IDENT tokens
context.getParent().removeLastChild();
Token token = (Token) context.getChild(0).getPayload();
Token newToken = new CommonToken(
new Pair<>(token.getTokenSource(), token.getInputStream()),
SqlBaseLexer.IDENTIFIER,
token.getChannel(),
token.getStartIndex(),
token.getStopIndex());
context.getParent().addChild(parser.createTerminalNode(context.getParent(), newToken));
}
}
}
@@ -1,161 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.parser;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenSource;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import static java.util.Objects.requireNonNull;
public class StatementSplitter
{
private final List<Statement> completeStatements;
private final String partialStatement;
public StatementSplitter(String sql)
{
this(sql, ImmutableSet.of(";"));
}
public StatementSplitter(String sql, Set<String> delimiters)
{
TokenSource tokens = getLexer(sql, delimiters);
ImmutableList.Builder<Statement> list = ImmutableList.builder();
StringBuilder sb = new StringBuilder();
while (true) {
Token token = tokens.nextToken();
if (token.getType() == Token.EOF) {
break;
}
if (token.getType() == SqlBaseParser.DELIMITER) {
String statement = sb.toString().trim();
if (!statement.isEmpty()) {
list.add(new Statement(statement, token.getText()));
}
sb = new StringBuilder();
}
else {
sb.append(token.getText());
}
}
this.completeStatements = list.build();
this.partialStatement = sb.toString().trim();
}
public List<Statement> getCompleteStatements()
{
return completeStatements;
}
public String getPartialStatement()
{
return partialStatement;
}
public static String squeezeStatement(String sql)
{
TokenSource tokens = getLexer(sql, ImmutableSet.of());
StringBuilder sb = new StringBuilder();
while (true) {
Token token = tokens.nextToken();
if (token.getType() == Token.EOF) {
break;
}
if (token.getType() == SqlBaseLexer.WS) {
sb.append(' ');
}
else {
sb.append(token.getText());
}
}
return sb.toString().trim();
}
public static boolean isEmptyStatement(String sql)
{
TokenSource tokens = getLexer(sql, ImmutableSet.of());
while (true) {
Token token = tokens.nextToken();
if (token.getType() == Token.EOF) {
return true;
}
if (token.getChannel() != Token.HIDDEN_CHANNEL) {
return false;
}
}
}
public static TokenSource getLexer(String sql, Set<String> terminators)
{
requireNonNull(sql, "sql is null");
CharStream stream = new CaseInsensitiveStream(CharStreams.fromString(sql));
return new DelimiterLexer(stream, terminators);
}
public static class Statement
{
private final String statement;
private final String terminator;
public Statement(String statement, String terminator)
{
this.statement = requireNonNull(statement, "statement is null");
this.terminator = requireNonNull(terminator, "terminator is null");
}
public String statement()
{
return statement;
}
public String terminator()
{
return terminator;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
Statement o = (Statement) obj;
return Objects.equals(statement, o.statement) &&
Objects.equals(terminator, o.terminator);
}
@Override
public int hashCode()
{
return Objects.hash(statement, terminator);
}
@Override
public String toString()
{
return statement + terminator;
}
}
}
@@ -1,121 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.testing;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import io.trino.sql.parser.ParsingException;
import io.trino.sql.parser.ParsingOptions;
import io.trino.sql.parser.SqlParser;
import io.trino.sql.tree.DefaultTraversalVisitor;
import io.trino.sql.tree.Node;
import io.trino.sql.tree.Statement;
import javax.annotation.Nullable;
import java.util.List;
import static io.trino.sql.SqlFormatter.formatSql;
import static io.trino.sql.parser.ParsingOptions.DecimalLiteralTreatment.AS_DOUBLE;
import static java.lang.String.format;
public final class TreeAssertions
{
private TreeAssertions() {}
public static void assertFormattedSql(SqlParser sqlParser, Node expected)
{
ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE /* anything */);
assertFormattedSql(sqlParser, parsingOptions, expected);
}
public static void assertFormattedSql(SqlParser sqlParser, ParsingOptions parsingOptions, Node expected)
{
String formatted = formatSql(expected);
// verify round-trip of formatting already-formatted SQL
Statement actual = parseFormatted(sqlParser, parsingOptions, formatted, expected);
assertEquals(formatSql(actual), formatted);
// compare parsed tree with parsed tree of formatted SQL
if (!actual.equals(expected)) {
// simplify finding the non-equal part of the tree
assertListEquals(linearizeTree(actual), linearizeTree(expected));
}
assertEquals(actual, expected);
}
private static Statement parseFormatted(SqlParser sqlParser, ParsingOptions parsingOptions, String sql, Node tree)
{
try {
return sqlParser.createStatement(sql, parsingOptions);
}
catch (ParsingException e) {
String message = format("failed to parse formatted SQL: %s\nerror: %s\ntree: %s", sql, e.getMessage(), tree);
throw new AssertionError(message, e);
}
}
private static List<Node> linearizeTree(Node tree)
{
ImmutableList.Builder<Node> nodes = ImmutableList.builder();
new DefaultTraversalVisitor<Void>()
{
@Override
public Void process(Node node, @Nullable Void context)
{
super.process(node, context);
nodes.add(node);
return null;
}
}.process(tree, null);
return nodes.build();
}
private static <T> void assertListEquals(List<T> actual, List<T> expected)
{
if (actual.size() != expected.size()) {
throw new AssertionError(format("Lists not equal in size%n%s", formatLists(actual, expected)));
}
if (!actual.equals(expected)) {
throw new AssertionError(format("Lists not equal at index %s%n%s",
differingIndex(actual, expected), formatLists(actual, expected)));
}
}
private static <T> String formatLists(List<T> actual, List<T> expected)
{
Joiner joiner = Joiner.on("\n ");
return format("Actual [%s]:%n %s%nExpected [%s]:%n %s%n",
actual.size(), joiner.join(actual),
expected.size(), joiner.join(expected));
}
private static <T> int differingIndex(List<T> actual, List<T> expected)
{
for (int i = 0; i < actual.size(); i++) {
if (!actual.get(i).equals(expected.get(i))) {
return i;
}
}
return actual.size();
}
private static <T> void assertEquals(T actual, T expected)
{
if (!actual.equals(expected)) {
throw new AssertionError(format("expected [%s] but found [%s]", expected, actual));
}
}
}
@@ -1,112 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class AddColumn
extends Statement
{
private final QualifiedName name;
private final ColumnDefinition column;
private final boolean tableExists;
private final boolean columnNotExists;
public AddColumn(QualifiedName name, ColumnDefinition column, boolean tableExists, boolean columnNotExists)
{
this(Optional.empty(), name, column, tableExists, columnNotExists);
}
public AddColumn(NodeLocation location, QualifiedName name, ColumnDefinition column, boolean tableExists, boolean columnNotExists)
{
this(Optional.of(location), name, column, tableExists, columnNotExists);
}
private AddColumn(Optional<NodeLocation> location, QualifiedName name, ColumnDefinition column, boolean tableExists, boolean columnNotExists)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.column = requireNonNull(column, "column is null");
this.tableExists = tableExists;
this.columnNotExists = columnNotExists;
}
public QualifiedName getName()
{
return name;
}
public ColumnDefinition getColumn()
{
return column;
}
public boolean isTableExists()
{
return tableExists;
}
public boolean isColumnNotExists()
{
return columnNotExists;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitAddColumn(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(column);
}
@Override
public int hashCode()
{
return Objects.hash(name, column);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
AddColumn o = (AddColumn) obj;
return Objects.equals(name, o.name) &&
Objects.equals(column, o.column);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("column", column)
.toString();
}
}
@@ -1,123 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class AliasedRelation
extends Relation
{
private final Relation relation;
private final Identifier alias;
private final List<Identifier> columnNames;
public AliasedRelation(Relation relation, Identifier alias, List<Identifier> columnNames)
{
this(Optional.empty(), relation, alias, columnNames);
}
public AliasedRelation(NodeLocation location, Relation relation, Identifier alias, List<Identifier> columnNames)
{
this(Optional.of(location), relation, alias, columnNames);
}
private AliasedRelation(Optional<NodeLocation> location, Relation relation, Identifier alias, List<Identifier> columnNames)
{
super(location);
requireNonNull(relation, "relation is null");
requireNonNull(alias, "alias is null");
this.relation = relation;
this.alias = alias;
this.columnNames = columnNames;
}
public Relation getRelation()
{
return relation;
}
public Identifier getAlias()
{
return alias;
}
public List<Identifier> getColumnNames()
{
return columnNames;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitAliasedRelation(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(relation);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("relation", relation)
.add("alias", alias)
.add("columnNames", columnNames)
.omitNullValues()
.toString();
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AliasedRelation that = (AliasedRelation) o;
return Objects.equals(relation, that.relation) &&
Objects.equals(alias, that.alias) &&
Objects.equals(columnNames, that.columnNames);
}
@Override
public int hashCode()
{
return Objects.hash(relation, alias, columnNames);
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
AliasedRelation otherRelation = (AliasedRelation) other;
return alias.equals(otherRelation.alias) && Objects.equals(columnNames, otherRelation.columnNames);
}
}
@@ -1,128 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class AllColumns
extends SelectItem
{
private final List<Identifier> aliases;
private final Optional<Expression> target;
public AllColumns()
{
this(Optional.empty(), Optional.empty(), ImmutableList.of());
}
public AllColumns(Expression target)
{
this(Optional.empty(), Optional.of(target), ImmutableList.of());
}
public AllColumns(Expression target, List<Identifier> aliases)
{
this(Optional.empty(), Optional.of(target), aliases);
}
public AllColumns(NodeLocation location, Optional<Expression> target, List<Identifier> aliases)
{
this(Optional.of(location), target, aliases);
}
public AllColumns(Optional<NodeLocation> location, Optional<Expression> target, List<Identifier> aliases)
{
super(location);
this.aliases = ImmutableList.copyOf(requireNonNull(aliases, "aliases is null"));
this.target = requireNonNull(target, "target is null");
}
public List<Identifier> getAliases()
{
return aliases;
}
public Optional<Expression> getTarget()
{
return target;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitAllColumns(this, context);
}
@Override
public List<Node> getChildren()
{
return target.map(ImmutableList::<Node>of)
.orElse(ImmutableList.of());
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AllColumns other = (AllColumns) o;
return Objects.equals(aliases, other.aliases) &&
Objects.equals(target, other.target);
}
@Override
public int hashCode()
{
return Objects.hash(aliases, target);
}
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
target.ifPresent(value -> builder.append(value).append("."));
builder.append("*");
if (!aliases.isEmpty()) {
builder.append(" (");
Joiner.on(", ").appendTo(builder, aliases);
builder.append(")");
}
return builder.toString();
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
return aliases.equals(((AllColumns) other).aliases);
}
}
@@ -1,71 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Optional;
public class AllRows
extends Expression
{
public AllRows()
{
this(Optional.empty());
}
public AllRows(NodeLocation location)
{
this(Optional.of(location));
}
public AllRows(Optional<NodeLocation> location)
{
super(location);
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitAllRows(this, context);
}
@Override
public List<? extends Node> getChildren()
{
return ImmutableList.of();
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
return (o != null) && (getClass() == o.getClass());
}
@Override
public int hashCode()
{
return getClass().hashCode();
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,99 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class Analyze
extends Statement
{
private final QualifiedName tableName;
private final List<Property> properties;
public Analyze(QualifiedName tableName, List<Property> properties)
{
this(Optional.empty(), tableName, properties);
}
public Analyze(NodeLocation location, QualifiedName tableName, List<Property> properties)
{
this(Optional.of(location), tableName, properties);
}
private Analyze(Optional<NodeLocation> location, QualifiedName tableName, List<Property> properties)
{
super(location);
this.tableName = requireNonNull(tableName, "tableName is null");
this.properties = ImmutableList.copyOf(requireNonNull(properties, "properties is null"));
}
public QualifiedName getTableName()
{
return tableName;
}
public List<Property> getProperties()
{
return properties;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitAnalyze(this, context);
}
@Override
public List<? extends Node> getChildren()
{
return properties;
}
@Override
public int hashCode()
{
return Objects.hash(tableName, properties);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
Analyze o = (Analyze) obj;
return Objects.equals(tableName, o.tableName) &&
Objects.equals(properties, o.properties);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("tableName", tableName)
.add("properties", properties)
.toString();
}
}
@@ -1,96 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class AnchorPattern
extends RowPattern
{
public enum Type
{
PARTITION_START,
PARTITION_END
}
private final Type type;
public AnchorPattern(NodeLocation location, Type type)
{
this(Optional.of(location), type);
}
private AnchorPattern(Optional<NodeLocation> location, Type type)
{
super(location);
this.type = requireNonNull(type, "type is null");
}
public Type getType()
{
return type;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitAnchorPattern(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
AnchorPattern o = (AnchorPattern) obj;
return Objects.equals(type, o.type);
}
@Override
public int hashCode()
{
return getClass().hashCode();
}
@Override
public String toString()
{
return toStringHelper(this)
.add("type", type)
.toString();
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,125 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
public class ArithmeticBinaryExpression
extends Expression
{
public enum Operator
{
ADD("+"),
SUBTRACT("-"),
MULTIPLY("*"),
DIVIDE("/"),
MODULUS("%");
private final String value;
Operator(String value)
{
this.value = value;
}
public String getValue()
{
return value;
}
}
private final Operator operator;
private final Expression left;
private final Expression right;
public ArithmeticBinaryExpression(Operator operator, Expression left, Expression right)
{
this(Optional.empty(), operator, left, right);
}
public ArithmeticBinaryExpression(NodeLocation location, Operator operator, Expression left, Expression right)
{
this(Optional.of(location), operator, left, right);
}
private ArithmeticBinaryExpression(Optional<NodeLocation> location, Operator operator, Expression left, Expression right)
{
super(location);
this.operator = operator;
this.left = left;
this.right = right;
}
public Operator getOperator()
{
return operator;
}
public Expression getLeft()
{
return left;
}
public Expression getRight()
{
return right;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitArithmeticBinary(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(left, right);
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ArithmeticBinaryExpression that = (ArithmeticBinaryExpression) o;
return (operator == that.operator) &&
Objects.equals(left, that.left) &&
Objects.equals(right, that.right);
}
@Override
public int hashCode()
{
return Objects.hash(operator, left, right);
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
return operator == ((ArithmeticBinaryExpression) other).operator;
}
}
@@ -1,128 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class ArithmeticUnaryExpression
extends Expression
{
public enum Sign
{
PLUS,
MINUS
}
private final Expression value;
private final Sign sign;
public ArithmeticUnaryExpression(Sign sign, Expression value)
{
this(Optional.empty(), sign, value);
}
public ArithmeticUnaryExpression(NodeLocation location, Sign sign, Expression value)
{
this(Optional.of(location), sign, value);
}
private ArithmeticUnaryExpression(Optional<NodeLocation> location, Sign sign, Expression value)
{
super(location);
requireNonNull(value, "value is null");
requireNonNull(sign, "sign is null");
this.value = value;
this.sign = sign;
}
public static ArithmeticUnaryExpression positive(NodeLocation location, Expression value)
{
return new ArithmeticUnaryExpression(Optional.of(location), Sign.PLUS, value);
}
public static ArithmeticUnaryExpression negative(NodeLocation location, Expression value)
{
return new ArithmeticUnaryExpression(Optional.of(location), Sign.MINUS, value);
}
public static ArithmeticUnaryExpression positive(Expression value)
{
return new ArithmeticUnaryExpression(Optional.empty(), Sign.PLUS, value);
}
public static ArithmeticUnaryExpression negative(Expression value)
{
return new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, value);
}
public Expression getValue()
{
return value;
}
public Sign getSign()
{
return sign;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitArithmeticUnary(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(value);
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ArithmeticUnaryExpression that = (ArithmeticUnaryExpression) o;
return Objects.equals(value, that.value) &&
(sign == that.sign);
}
@Override
public int hashCode()
{
return Objects.hash(value, sign);
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
return sign == ((ArithmeticUnaryExpression) other).sign;
}
}
@@ -1,89 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class ArrayConstructor
extends Expression
{
public static final String ARRAY_CONSTRUCTOR = "ARRAY_CONSTRUCTOR";
private final List<Expression> values;
public ArrayConstructor(List<Expression> values)
{
this(Optional.empty(), values);
}
public ArrayConstructor(NodeLocation location, List<Expression> values)
{
this(Optional.of(location), values);
}
private ArrayConstructor(Optional<NodeLocation> location, List<Expression> values)
{
super(location);
requireNonNull(values, "values is null");
this.values = ImmutableList.copyOf(values);
}
public List<Expression> getValues()
{
return values;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitArrayConstructor(this, context);
}
@Override
public List<? extends Node> getChildren()
{
return values;
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ArrayConstructor that = (ArrayConstructor) o;
return Objects.equals(values, that.values);
}
@Override
public int hashCode()
{
return values.hashCode();
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
File diff suppressed because it is too large Load Diff
@@ -1,95 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
public class AtTimeZone
extends Expression
{
private final Expression value;
private final Expression timeZone;
public AtTimeZone(Expression value, Expression timeZone)
{
this(Optional.empty(), value, timeZone);
}
public AtTimeZone(NodeLocation location, Expression value, Expression timeZone)
{
this(Optional.of(location), value, timeZone);
}
private AtTimeZone(Optional<NodeLocation> location, Expression value, Expression timeZone)
{
super(location);
checkArgument(timeZone instanceof IntervalLiteral || timeZone instanceof StringLiteral, "timeZone must be IntervalLiteral or StringLiteral");
this.value = requireNonNull(value, "value is null");
this.timeZone = requireNonNull(timeZone, "timeZone is null");
}
public Expression getValue()
{
return value;
}
public Expression getTimeZone()
{
return timeZone;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitAtTimeZone(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(value, timeZone);
}
@Override
public int hashCode()
{
return Objects.hash(value, timeZone);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
AtTimeZone atTimeZone = (AtTimeZone) obj;
return Objects.equals(value, atTimeZone.value) && Objects.equals(timeZone, atTimeZone.timeZone);
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,107 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class BetweenPredicate
extends Expression
{
private final Expression value;
private final Expression min;
private final Expression max;
public BetweenPredicate(Expression value, Expression min, Expression max)
{
this(Optional.empty(), value, min, max);
}
public BetweenPredicate(NodeLocation location, Expression value, Expression min, Expression max)
{
this(Optional.of(location), value, min, max);
}
private BetweenPredicate(Optional<NodeLocation> location, Expression value, Expression min, Expression max)
{
super(location);
requireNonNull(value, "value is null");
requireNonNull(min, "min is null");
requireNonNull(max, "max is null");
this.value = value;
this.min = min;
this.max = max;
}
public Expression getValue()
{
return value;
}
public Expression getMin()
{
return min;
}
public Expression getMax()
{
return max;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitBetweenPredicate(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(value, min, max);
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BetweenPredicate that = (BetweenPredicate) o;
return Objects.equals(value, that.value) &&
Objects.equals(min, that.min) &&
Objects.equals(max, that.max);
}
@Override
public int hashCode()
{
return Objects.hash(value, min, max);
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,109 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.io.BaseEncoding;
import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
import io.trino.sql.parser.ParsingException;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
public class BinaryLiteral
extends Literal
{
// the grammar could possibly include whitespace in the value it passes to us
private static final Pattern WHITESPACE_PATTERN = Pattern.compile("[ \\r\\n\\t]");
private static final Pattern NOT_HEX_DIGIT_PATTERN = Pattern.compile(".*[^A-F0-9].*");
private final Slice value;
public BinaryLiteral(String value)
{
this(Optional.empty(), value);
}
public BinaryLiteral(Optional<NodeLocation> location, String value)
{
super(location);
requireNonNull(value, "value is null");
String hexString = WHITESPACE_PATTERN.matcher(value).replaceAll("").toUpperCase(ENGLISH);
if (NOT_HEX_DIGIT_PATTERN.matcher(hexString).matches()) {
throw new ParsingException("Binary literal can only contain hexadecimal digits", location.get());
}
if (hexString.length() % 2 != 0) {
throw new ParsingException("Binary literal must contain an even number of digits", location.get());
}
this.value = Slices.wrappedBuffer(BaseEncoding.base16().decode(hexString));
}
public BinaryLiteral(NodeLocation location, String value)
{
this(Optional.of(location), value);
}
/**
* Return the valued as a hex-formatted string with upper-case characters
*/
public String toHexString()
{
return BaseEncoding.base16().encode(value.getBytes());
}
public Slice getValue()
{
return value;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitBinaryLiteral(this, context);
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BinaryLiteral that = (BinaryLiteral) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode()
{
return value.hashCode();
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
return Objects.equals(value, ((BinaryLiteral) other).value);
}
}
@@ -1,121 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
/**
* "$INTERNAL$BIND"(value, targetFunction)
* <p>
* When invoked, the returned function inserts the given value as
* the leading argument to the targetFunction. The other arguments are
* passed unchanged.
* <p>
* Bind is fundamentally first class, just like function applications.
* It requires special treatment from the type system. There is no way
* to write out the type of `bind`. The return type of `bind` is function.
* Its type looks somewhat like:
* <p><ul>
* <li>X, (X) -> Y => () -> Y
* <li>X1, (X1, X2) -> Y => (X2) -> Y
* <li>X1, (X1, X2, X3) -> Y => (X2, X3) -> Y
* <li>X1, (X1, X2, X3, X4) -> Y => (X2, X3, X4) -> Y
* <li>...
* </ul>
* <p>
* Lambda capturing is implemented through desugaring in Trino.
* This expression facilitates desugaring.
*/
public class BindExpression
extends Expression
{
private final List<Expression> values;
// Function expression must be of function type.
// It is not necessarily a lambda. For example, it can be another bind expression.
private final Expression function;
public BindExpression(List<Expression> values, Expression function)
{
this(Optional.empty(), values, function);
}
public BindExpression(NodeLocation location, List<Expression> values, Expression function)
{
this(Optional.of(location), values, function);
}
private BindExpression(Optional<NodeLocation> location, List<Expression> values, Expression function)
{
super(location);
this.values = requireNonNull(values, "values is null");
this.function = requireNonNull(function, "function is null");
}
public List<Expression> getValues()
{
return values;
}
public Expression getFunction()
{
return function;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitBindExpression(this, context);
}
@Override
public List<Node> getChildren()
{
ImmutableList.Builder<Node> nodes = ImmutableList.builder();
return nodes.addAll(values)
.add(function)
.build();
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BindExpression that = (BindExpression) o;
return Objects.equals(values, that.values) &&
Objects.equals(function, that.function);
}
@Override
public int hashCode()
{
return Objects.hash(values, function);
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,89 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
public class BooleanLiteral
extends Literal
{
public static final BooleanLiteral TRUE_LITERAL = new BooleanLiteral(Optional.empty(), "true");
public static final BooleanLiteral FALSE_LITERAL = new BooleanLiteral(Optional.empty(), "false");
private final boolean value;
public BooleanLiteral(String value)
{
this(Optional.empty(), value);
}
public BooleanLiteral(NodeLocation location, String value)
{
this(Optional.of(location), value);
}
private BooleanLiteral(Optional<NodeLocation> location, String value)
{
super(location);
requireNonNull(value, "value is null");
checkArgument(value.toLowerCase(ENGLISH).equals("true") || value.toLowerCase(ENGLISH).equals("false"));
this.value = value.toLowerCase(ENGLISH).equals("true");
}
public boolean getValue()
{
return value;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitBooleanLiteral(this, context);
}
@Override
public int hashCode()
{
return Objects.hash(value);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
BooleanLiteral other = (BooleanLiteral) obj;
return Objects.equals(this.value, other.value);
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
return value == ((BooleanLiteral) other).value;
}
}
@@ -1,98 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public final class Call
extends Statement
{
private final QualifiedName name;
private final List<CallArgument> arguments;
public Call(QualifiedName name, List<CallArgument> arguments)
{
this(Optional.empty(), name, arguments);
}
public Call(NodeLocation location, QualifiedName name, List<CallArgument> arguments)
{
this(Optional.of(location), name, arguments);
}
public Call(Optional<NodeLocation> location, QualifiedName name, List<CallArgument> arguments)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.arguments = ImmutableList.copyOf(requireNonNull(arguments, "arguments is null"));
}
public QualifiedName getName()
{
return name;
}
public List<CallArgument> getArguments()
{
return arguments;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCall(this, context);
}
@Override
public List<? extends Node> getChildren()
{
return arguments;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
Call o = (Call) obj;
return Objects.equals(name, o.name) &&
Objects.equals(arguments, o.arguments);
}
@Override
public int hashCode()
{
return Objects.hash(name, arguments);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("arguments", arguments)
.toString();
}
}
@@ -1,109 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public final class CallArgument
extends Node
{
private final Optional<Identifier> name;
private final Expression value;
public CallArgument(Expression value)
{
this(Optional.empty(), Optional.empty(), value);
}
public CallArgument(NodeLocation location, Expression value)
{
this(Optional.of(location), Optional.empty(), value);
}
public CallArgument(Identifier name, Expression value)
{
this(Optional.empty(), Optional.of(name), value);
}
public CallArgument(NodeLocation location, Identifier name, Expression value)
{
this(Optional.of(location), Optional.of(name), value);
}
public CallArgument(Optional<NodeLocation> location, Optional<Identifier> name, Expression value)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.value = requireNonNull(value, "value is null");
}
public Optional<Identifier> getName()
{
return name;
}
public Expression getValue()
{
return value;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCallArgument(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(value);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
CallArgument o = (CallArgument) obj;
return Objects.equals(name, o.name) &&
Objects.equals(value, o.value);
}
@Override
public int hashCode()
{
return Objects.hash(name, value);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name.orElse(null))
.add("value", value)
.omitNullValues()
.toString();
}
}
@@ -1,138 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
public final class Cast
extends Expression
{
private final Expression expression;
private final DataType type;
private final boolean safe;
private final boolean typeOnly;
public Cast(Expression expression, DataType type)
{
this(Optional.empty(), expression, type, false, false);
}
public Cast(Expression expression, DataType type, boolean safe)
{
this(Optional.empty(), expression, type, safe, false);
}
public Cast(Expression expression, DataType type, boolean safe, boolean typeOnly)
{
this(Optional.empty(), expression, type, safe, typeOnly);
}
public Cast(NodeLocation location, Expression expression, DataType type)
{
this(Optional.of(location), expression, type, false, false);
}
public Cast(NodeLocation location, Expression expression, DataType type, boolean safe)
{
this(Optional.of(location), expression, type, safe, false);
}
public Cast(NodeLocation location, Expression expression, DataType type, boolean safe, boolean typeOnly)
{
this(Optional.of(location), expression, type, safe, typeOnly);
}
private Cast(Optional<NodeLocation> location, Expression expression, DataType type, boolean safe, boolean typeOnly)
{
super(location);
requireNonNull(expression, "expression is null");
this.expression = expression;
this.type = type;
this.safe = safe;
this.typeOnly = typeOnly;
}
public Expression getExpression()
{
return expression;
}
public DataType getType()
{
return type;
}
public boolean isSafe()
{
return safe;
}
public boolean isTypeOnly()
{
return typeOnly;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCast(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(expression, type);
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Cast cast = (Cast) o;
return safe == cast.safe &&
typeOnly == cast.typeOnly &&
expression.equals(cast.expression) &&
type.equals(cast.type);
}
@Override
public int hashCode()
{
return Objects.hash(expression, type, safe, typeOnly);
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
Cast otherCast = (Cast) other;
return safe == otherCast.safe &&
typeOnly == otherCast.typeOnly;
}
}
@@ -1,93 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.base.CharMatcher;
import io.airlift.slice.Slice;
import java.util.Objects;
import java.util.Optional;
import static io.airlift.slice.Slices.utf8Slice;
import static java.util.Objects.requireNonNull;
public class CharLiteral
extends Literal
{
private final String value;
private final Slice slice;
public CharLiteral(String value)
{
this(Optional.empty(), value);
}
public CharLiteral(NodeLocation location, String value)
{
this(Optional.of(location), value);
}
public CharLiteral(Optional<NodeLocation> location, String value)
{
super(location);
requireNonNull(value, "value is null");
this.value = value;
this.slice = utf8Slice(CharMatcher.is(' ').trimTrailingFrom(value));
}
public String getValue()
{
return value;
}
public Slice getSlice()
{
return slice;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCharLiteral(this, context);
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CharLiteral that = (CharLiteral) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode()
{
return Objects.hash(value);
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
return Objects.equals(value, ((CharLiteral) other).value);
}
}
@@ -1,99 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
public class CoalesceExpression
extends Expression
{
private final List<Expression> operands;
public CoalesceExpression(Expression first, Expression second, Expression... additional)
{
this(Optional.empty(), ImmutableList.<Expression>builder()
.add(first, second)
.add(additional)
.build());
}
public CoalesceExpression(List<Expression> operands)
{
this(Optional.empty(), operands);
}
public CoalesceExpression(NodeLocation location, List<Expression> operands)
{
this(Optional.of(location), operands);
}
private CoalesceExpression(Optional<NodeLocation> location, List<Expression> operands)
{
super(location);
requireNonNull(operands, "operands is null");
checkArgument(operands.size() >= 2, "must have at least two operands");
this.operands = ImmutableList.copyOf(operands);
}
public List<Expression> getOperands()
{
return operands;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCoalesceExpression(this, context);
}
@Override
public List<? extends Node> getChildren()
{
return operands;
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CoalesceExpression that = (CoalesceExpression) o;
return Objects.equals(operands, that.operands);
}
@Override
public int hashCode()
{
return operands.hashCode();
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,125 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public final class ColumnDefinition
extends TableElement
{
private final Identifier name;
private final DataType type;
private final boolean nullable;
private final List<Property> properties;
private final Optional<String> comment;
public ColumnDefinition(Identifier name, DataType type, boolean nullable, List<Property> properties, Optional<String> comment)
{
this(Optional.empty(), name, type, nullable, properties, comment);
}
public ColumnDefinition(NodeLocation location, Identifier name, DataType type, boolean nullable, List<Property> properties, Optional<String> comment)
{
this(Optional.of(location), name, type, nullable, properties, comment);
}
private ColumnDefinition(Optional<NodeLocation> location, Identifier name, DataType type, boolean nullable, List<Property> properties, Optional<String> comment)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.type = requireNonNull(type, "type is null");
this.nullable = nullable;
this.properties = requireNonNull(properties, "properties is null");
this.comment = requireNonNull(comment, "comment is null");
}
public Identifier getName()
{
return name;
}
public DataType getType()
{
return type;
}
public boolean isNullable()
{
return nullable;
}
public List<Property> getProperties()
{
return properties;
}
public Optional<String> getComment()
{
return comment;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitColumnDefinition(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
ColumnDefinition o = (ColumnDefinition) obj;
return Objects.equals(this.name, o.name) &&
Objects.equals(this.type, o.type) &&
this.nullable == o.nullable &&
Objects.equals(properties, o.properties) &&
Objects.equals(this.comment, o.comment);
}
@Override
public int hashCode()
{
return Objects.hash(name, type, properties, comment, nullable);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("type", type)
.add("nullable", nullable)
.add("properties", properties)
.add("comment", comment)
.toString();
}
}
@@ -1,112 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public final class Comment
extends Statement
{
public enum Type
{
TABLE, COLUMN
}
private final Type type;
private final QualifiedName name;
private final Optional<String> comment;
public Comment(Type type, QualifiedName name, Optional<String> comment)
{
this(Optional.empty(), type, name, comment);
}
public Comment(NodeLocation location, Type type, QualifiedName name, Optional<String> comment)
{
this(Optional.of(location), type, name, comment);
}
private Comment(Optional<NodeLocation> location, Type type, QualifiedName name, Optional<String> comment)
{
super(location);
this.type = requireNonNull(type, "type is null");
this.name = requireNonNull(name, "name is null");
this.comment = requireNonNull(comment, "comment is null");
}
public Type getType()
{
return type;
}
public QualifiedName getName()
{
return name;
}
public Optional<String> getComment()
{
return comment;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitComment(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return Objects.hash(type, name, comment);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
Comment o = (Comment) obj;
return type == o.type &&
Objects.equals(name, o.name) &&
Objects.equals(comment, o.comment);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("type", type)
.add("name", name)
.add("comment", comment)
.toString();
}
}
@@ -1,74 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Optional;
public final class Commit
extends Statement
{
public Commit()
{
this(Optional.empty());
}
public Commit(NodeLocation location)
{
this(Optional.of(location));
}
private Commit(Optional<NodeLocation> location)
{
super(location);
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCommit(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return getClass().hashCode();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
return true;
}
@Override
public String toString()
{
return "COMMIT";
}
}
@@ -1,177 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class ComparisonExpression
extends Expression
{
private final Operator operator;
private final Expression left;
private final Expression right;
public ComparisonExpression(Operator operator, Expression left, Expression right)
{
this(Optional.empty(), operator, left, right);
}
public ComparisonExpression(NodeLocation location, Operator operator, Expression left, Expression right)
{
this(Optional.of(location), operator, left, right);
}
private ComparisonExpression(Optional<NodeLocation> location, Operator operator, Expression left, Expression right)
{
super(location);
requireNonNull(operator, "operator is null");
requireNonNull(left, "left is null");
requireNonNull(right, "right is null");
this.operator = operator;
this.left = left;
this.right = right;
}
public Operator getOperator()
{
return operator;
}
public Expression getLeft()
{
return left;
}
public Expression getRight()
{
return right;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitComparisonExpression(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(left, right);
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ComparisonExpression that = (ComparisonExpression) o;
return (operator == that.operator) &&
Objects.equals(left, that.left) &&
Objects.equals(right, that.right);
}
@Override
public int hashCode()
{
return Objects.hash(operator, left, right);
}
public enum Operator
{
EQUAL("="),
NOT_EQUAL("<>"),
LESS_THAN("<"),
LESS_THAN_OR_EQUAL("<="),
GREATER_THAN(">"),
GREATER_THAN_OR_EQUAL(">="),
IS_DISTINCT_FROM("IS DISTINCT FROM");
private final String value;
Operator(String value)
{
this.value = value;
}
public String getValue()
{
return value;
}
public Operator flip()
{
switch (this) {
case EQUAL:
return EQUAL;
case NOT_EQUAL:
return NOT_EQUAL;
case LESS_THAN:
return GREATER_THAN;
case LESS_THAN_OR_EQUAL:
return GREATER_THAN_OR_EQUAL;
case GREATER_THAN:
return LESS_THAN;
case GREATER_THAN_OR_EQUAL:
return LESS_THAN_OR_EQUAL;
case IS_DISTINCT_FROM:
return IS_DISTINCT_FROM;
}
throw new IllegalArgumentException("Unsupported comparison: " + this);
}
public Operator negate()
{
switch (this) {
case EQUAL:
return NOT_EQUAL;
case NOT_EQUAL:
return EQUAL;
case LESS_THAN:
return GREATER_THAN_OR_EQUAL;
case LESS_THAN_OR_EQUAL:
return GREATER_THAN;
case GREATER_THAN:
return LESS_THAN_OR_EQUAL;
case GREATER_THAN_OR_EQUAL:
return LESS_THAN;
case IS_DISTINCT_FROM:
// Cannot negate
break;
}
throw new IllegalArgumentException("Unsupported comparison: " + this);
}
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
return operator == ((ComparisonExpression) other).operator;
}
}
@@ -1,130 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class CreateMaterializedView
extends Statement
{
private final QualifiedName name;
private final Query query;
private final boolean replace;
private final boolean notExists;
private final List<Property> properties;
private final Optional<String> comment;
public CreateMaterializedView(Optional<NodeLocation> location,
QualifiedName name,
Query query,
boolean replace,
boolean notExists,
List<Property> properties,
Optional<String> comment)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.query = requireNonNull(query, "query is null");
this.replace = replace;
this.notExists = notExists;
this.properties = properties;
this.comment = comment;
}
public QualifiedName getName()
{
return name;
}
public Query getQuery()
{
return query;
}
public boolean isReplace()
{
return replace;
}
public boolean isNotExists()
{
return notExists;
}
public List<Property> getProperties()
{
return properties;
}
public Optional<String> getComment()
{
return comment;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCreateMaterializedView(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(query);
}
@Override
public int hashCode()
{
return Objects.hash(name, query, replace, notExists, properties, comment);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
CreateMaterializedView o = (CreateMaterializedView) obj;
return Objects.equals(name, o.name)
&& Objects.equals(query, o.query)
&& Objects.equals(replace, o.replace)
&& Objects.equals(notExists, o.notExists)
&& Objects.equals(properties, o.properties)
&& Objects.equals(comment, o.comment);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("query", query)
.add("replace", replace)
.add("notExists", notExists)
.add("properties", properties)
.add("comment", comment)
.toString();
}
}
@@ -1,107 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class CreateRole
extends Statement
{
private final Identifier name;
private final Optional<GrantorSpecification> grantor;
private final Optional<Identifier> catalog;
public CreateRole(Identifier name, Optional<GrantorSpecification> grantor, Optional<Identifier> catalog)
{
this(Optional.empty(), name, grantor, catalog);
}
public CreateRole(NodeLocation location, Identifier name, Optional<GrantorSpecification> grantor, Optional<Identifier> catalog)
{
this(Optional.of(location), name, grantor, catalog);
}
private CreateRole(Optional<NodeLocation> location, Identifier name, Optional<GrantorSpecification> grantor, Optional<Identifier> catalog)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.grantor = requireNonNull(grantor, "grantor is null");
this.catalog = requireNonNull(catalog, "catalog is null");
}
public Identifier getName()
{
return name;
}
public Optional<GrantorSpecification> getGrantor()
{
return grantor;
}
public Optional<Identifier> getCatalog()
{
return catalog;
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CreateRole that = (CreateRole) o;
return Objects.equals(name, that.name) &&
Objects.equals(grantor, that.grantor) &&
Objects.equals(catalog, that.catalog);
}
@Override
public int hashCode()
{
return Objects.hash(name, grantor, catalog);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("grantor", grantor)
.add("catalog", catalog)
.toString();
}
@Override
public List<? extends Node> getChildren()
{
return ImmutableList.of();
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCreateRole(this, context);
}
}
@@ -1,119 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class CreateSchema
extends Statement
{
private final QualifiedName schemaName;
private final boolean notExists;
private final List<Property> properties;
private final Optional<PrincipalSpecification> principal;
public CreateSchema(QualifiedName schemaName, boolean notExists, List<Property> properties)
{
this(Optional.empty(), schemaName, notExists, properties, Optional.empty());
}
public CreateSchema(QualifiedName schemaName, boolean notExists, List<Property> properties, Optional<PrincipalSpecification> principal)
{
this(Optional.empty(), schemaName, notExists, properties, principal);
}
public CreateSchema(NodeLocation location, QualifiedName schemaName, boolean notExists, List<Property> properties, Optional<PrincipalSpecification> principal)
{
this(Optional.of(location), schemaName, notExists, properties, principal);
}
private CreateSchema(Optional<NodeLocation> location, QualifiedName schemaName, boolean notExists, List<Property> properties, Optional<PrincipalSpecification> principal)
{
super(location);
this.schemaName = requireNonNull(schemaName, "schemaName is null");
this.notExists = notExists;
this.properties = ImmutableList.copyOf(requireNonNull(properties, "properties is null"));
this.principal = principal;
}
public QualifiedName getSchemaName()
{
return schemaName;
}
public boolean isNotExists()
{
return notExists;
}
public Optional<PrincipalSpecification> getPrincipal()
{
return principal;
}
public List<Property> getProperties()
{
return properties;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCreateSchema(this, context);
}
@Override
public List<Property> getChildren()
{
return properties;
}
@Override
public int hashCode()
{
return Objects.hash(schemaName, notExists, properties);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
CreateSchema o = (CreateSchema) obj;
return Objects.equals(schemaName, o.schemaName) &&
Objects.equals(notExists, o.notExists) &&
Objects.equals(properties, o.properties);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("schemaName", schemaName)
.add("notExists", notExists)
.add("properties", properties)
.toString();
}
}
@@ -1,128 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class CreateTable
extends Statement
{
private final QualifiedName name;
private final List<TableElement> elements;
private final boolean notExists;
private final List<Property> properties;
private final Optional<String> comment;
public CreateTable(QualifiedName name, List<TableElement> elements, boolean notExists, List<Property> properties, Optional<String> comment)
{
this(Optional.empty(), name, elements, notExists, properties, comment);
}
public CreateTable(NodeLocation location, QualifiedName name, List<TableElement> elements, boolean notExists, List<Property> properties, Optional<String> comment)
{
this(Optional.of(location), name, elements, notExists, properties, comment);
}
private CreateTable(Optional<NodeLocation> location, QualifiedName name, List<TableElement> elements, boolean notExists, List<Property> properties, Optional<String> comment)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.elements = ImmutableList.copyOf(requireNonNull(elements, "elements is null"));
this.notExists = notExists;
this.properties = requireNonNull(properties, "properties is null");
this.comment = requireNonNull(comment, "comment is null");
}
public QualifiedName getName()
{
return name;
}
public List<TableElement> getElements()
{
return elements;
}
public boolean isNotExists()
{
return notExists;
}
public List<Property> getProperties()
{
return properties;
}
public Optional<String> getComment()
{
return comment;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCreateTable(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.<Node>builder()
.addAll(elements)
.addAll(properties)
.build();
}
@Override
public int hashCode()
{
return Objects.hash(name, elements, notExists, properties, comment);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
CreateTable o = (CreateTable) obj;
return Objects.equals(name, o.name) &&
Objects.equals(elements, o.elements) &&
Objects.equals(notExists, o.notExists) &&
Objects.equals(properties, o.properties) &&
Objects.equals(comment, o.comment);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("elements", elements)
.add("notExists", notExists)
.add("properties", properties)
.add("comment", comment)
.toString();
}
}
@@ -1,146 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class CreateTableAsSelect
extends Statement
{
private final QualifiedName name;
private final Query query;
private final boolean notExists;
private final List<Property> properties;
private final boolean withData;
private final Optional<List<Identifier>> columnAliases;
private final Optional<String> comment;
public CreateTableAsSelect(QualifiedName name, Query query, boolean notExists, List<Property> properties, boolean withData, Optional<List<Identifier>> columnAliases, Optional<String> comment)
{
this(Optional.empty(), name, query, notExists, properties, withData, columnAliases, comment);
}
public CreateTableAsSelect(NodeLocation location, QualifiedName name, Query query, boolean notExists, List<Property> properties, boolean withData, Optional<List<Identifier>> columnAliases, Optional<String> comment)
{
this(Optional.of(location), name, query, notExists, properties, withData, columnAliases, comment);
}
private CreateTableAsSelect(Optional<NodeLocation> location, QualifiedName name, Query query, boolean notExists, List<Property> properties, boolean withData, Optional<List<Identifier>> columnAliases, Optional<String> comment)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.query = requireNonNull(query, "query is null");
this.notExists = notExists;
this.properties = ImmutableList.copyOf(requireNonNull(properties, "properties is null"));
this.withData = withData;
this.columnAliases = columnAliases;
this.comment = requireNonNull(comment, "comment is null");
}
public QualifiedName getName()
{
return name;
}
public Query getQuery()
{
return query;
}
public boolean isNotExists()
{
return notExists;
}
public List<Property> getProperties()
{
return properties;
}
public boolean isWithData()
{
return withData;
}
public Optional<List<Identifier>> getColumnAliases()
{
return columnAliases;
}
public Optional<String> getComment()
{
return comment;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCreateTableAsSelect(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.<Node>builder()
.add(query)
.addAll(properties)
.build();
}
@Override
public int hashCode()
{
return Objects.hash(name, query, properties, withData, columnAliases, comment);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
CreateTableAsSelect o = (CreateTableAsSelect) obj;
return Objects.equals(name, o.name)
&& Objects.equals(query, o.query)
&& Objects.equals(notExists, o.notExists)
&& Objects.equals(properties, o.properties)
&& Objects.equals(withData, o.withData)
&& Objects.equals(columnAliases, o.columnAliases)
&& Objects.equals(comment, o.comment);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("query", query)
.add("notExists", notExists)
.add("properties", properties)
.add("withData", withData)
.add("columnAliases", columnAliases)
.add("comment", comment)
.toString();
}
}
@@ -1,130 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class CreateView
extends Statement
{
public enum Security
{
INVOKER, DEFINER
}
private final QualifiedName name;
private final Query query;
private final boolean replace;
private final Optional<String> comment;
private final Optional<Security> security;
public CreateView(QualifiedName name, Query query, boolean replace, Optional<String> comment, Optional<Security> security)
{
this(Optional.empty(), name, query, replace, comment, security);
}
public CreateView(NodeLocation location, QualifiedName name, Query query, boolean replace, Optional<String> comment, Optional<Security> security)
{
this(Optional.of(location), name, query, replace, comment, security);
}
private CreateView(Optional<NodeLocation> location, QualifiedName name, Query query, boolean replace, Optional<String> comment, Optional<Security> security)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.query = requireNonNull(query, "query is null");
this.replace = replace;
this.comment = requireNonNull(comment, "comment is null");
this.security = requireNonNull(security, "security is null");
}
public QualifiedName getName()
{
return name;
}
public Query getQuery()
{
return query;
}
public boolean isReplace()
{
return replace;
}
public Optional<String> getComment()
{
return comment;
}
public Optional<Security> getSecurity()
{
return security;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCreateView(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(query);
}
@Override
public int hashCode()
{
return Objects.hash(name, query, replace, security);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
CreateView o = (CreateView) obj;
return Objects.equals(name, o.name)
&& Objects.equals(query, o.query)
&& Objects.equals(replace, o.replace)
&& Objects.equals(comment, o.comment)
&& Objects.equals(security, o.security);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("query", query)
.add("replace", replace)
.add("comment", comment)
.add("security", security)
.toString();
}
}
@@ -1,90 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public final class Cube
extends GroupingElement
{
private final List<Expression> columns;
public Cube(List<Expression> columns)
{
this(Optional.empty(), columns);
}
public Cube(NodeLocation location, List<Expression> columns)
{
this(Optional.of(location), columns);
}
private Cube(Optional<NodeLocation> location, List<Expression> columns)
{
super(location);
this.columns = ImmutableList.copyOf(requireNonNull(columns, "columns is null"));
}
@Override
public List<Expression> getExpressions()
{
return columns;
}
@Override
protected <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCube(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Cube cube = (Cube) o;
return Objects.equals(columns, cube.columns);
}
@Override
public int hashCode()
{
return Objects.hash(columns);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("columns", columns)
.toString();
}
}
@@ -1,69 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Optional;
public class CurrentCatalog
extends Expression
{
public CurrentCatalog(NodeLocation location)
{
this(Optional.of(location));
}
private CurrentCatalog(Optional<NodeLocation> location)
{
super(location);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCurrentCatalog(this, context);
}
@Override
public int hashCode()
{
return getClass().hashCode();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
return true;
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,69 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Optional;
public class CurrentPath
extends Expression
{
public CurrentPath(NodeLocation location)
{
this(Optional.of(location));
}
private CurrentPath(Optional<NodeLocation> location)
{
super(location);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCurrentPath(this, context);
}
@Override
public int hashCode()
{
return getClass().hashCode();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
return true;
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,69 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Optional;
public class CurrentSchema
extends Expression
{
public CurrentSchema(NodeLocation location)
{
this(Optional.of(location));
}
private CurrentSchema(Optional<NodeLocation> location)
{
super(location);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCurrentSchema(this, context);
}
@Override
public int hashCode()
{
return getClass().hashCode();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
return true;
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,132 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class CurrentTime
extends Expression
{
private final Function function;
private final Integer precision;
public enum Function
{
TIME("current_time"),
DATE("current_date"),
TIMESTAMP("current_timestamp"),
LOCALTIME("localtime"),
LOCALTIMESTAMP("localtimestamp");
private final String name;
Function(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
}
public CurrentTime(Function function)
{
this(Optional.empty(), function, null);
}
public CurrentTime(NodeLocation location, Function function)
{
this(Optional.of(location), function, null);
}
public CurrentTime(Function function, Integer precision)
{
this(Optional.empty(), function, precision);
}
public CurrentTime(NodeLocation location, Function function, Integer precision)
{
this(Optional.of(location), function, precision);
}
private CurrentTime(Optional<NodeLocation> location, Function function, Integer precision)
{
super(location);
requireNonNull(function, "function is null");
this.function = function;
this.precision = precision;
}
public Function getFunction()
{
return function;
}
public Integer getPrecision()
{
return precision;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCurrentTime(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if ((o == null) || (getClass() != o.getClass())) {
return false;
}
CurrentTime that = (CurrentTime) o;
return (function == that.function) &&
Objects.equals(precision, that.precision);
}
@Override
public int hashCode()
{
return Objects.hash(function, precision);
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
CurrentTime otherNode = (CurrentTime) other;
return (function == otherNode.function) &&
Objects.equals(precision, otherNode.precision);
}
}
@@ -1,74 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Optional;
public class CurrentUser
extends Expression
{
public CurrentUser()
{
this(Optional.empty());
}
public CurrentUser(NodeLocation location)
{
this(Optional.of(location));
}
private CurrentUser(Optional<NodeLocation> location)
{
super(location);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitCurrentUser(this, context);
}
@Override
public int hashCode()
{
return getClass().hashCode();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
return true;
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,25 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import java.util.Optional;
public abstract class DataType
extends Expression
{
public DataType(Optional<NodeLocation> location)
{
super(location);
}
}
@@ -1,31 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import java.util.Optional;
public abstract class DataTypeParameter
extends Node
{
protected DataTypeParameter(Optional<NodeLocation> location)
{
super(location);
}
@Override
protected <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDataTypeParameter(this, context);
}
}
@@ -1,109 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class DateTimeDataType
extends DataType
{
public enum Type
{
TIMESTAMP, TIME
}
private final Type type;
private final boolean withTimeZone;
private final Optional<DataTypeParameter> precision;
public DateTimeDataType(NodeLocation location, Type type, boolean withTimeZone, Optional<DataTypeParameter> precision)
{
this(Optional.of(location), type, withTimeZone, precision);
}
public DateTimeDataType(Optional<NodeLocation> location, Type type, boolean withTimeZone, Optional<DataTypeParameter> precision)
{
super(location);
this.type = requireNonNull(type, "type is null");
this.withTimeZone = withTimeZone;
this.precision = requireNonNull(precision, "precision is null");
}
public Type getType()
{
return type;
}
public boolean isWithTimeZone()
{
return withTimeZone;
}
public Optional<DataTypeParameter> getPrecision()
{
return precision;
}
@Override
public List<? extends Node> getChildren()
{
return ImmutableList.of();
}
@Override
protected <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDateTimeType(this, context);
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DateTimeDataType that = (DateTimeDataType) o;
return withTimeZone == that.withTimeZone &&
type == that.type &&
precision.equals(that.precision);
}
@Override
public int hashCode()
{
return Objects.hash(type, withTimeZone, precision);
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
DateTimeDataType otherType = (DateTimeDataType) other;
return type.equals(otherType.type) &&
withTimeZone == otherType.withTimeZone &&
precision.equals(otherType.precision);
}
}
@@ -1,89 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class Deallocate
extends Statement
{
private final Identifier name;
public Deallocate(NodeLocation location, Identifier name)
{
this(Optional.of(location), name);
}
public Deallocate(Identifier name)
{
this(Optional.empty(), name);
}
private Deallocate(Optional<NodeLocation> location, Identifier name)
{
super(location);
this.name = requireNonNull(name, "name is null");
}
public Identifier getName()
{
return name;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDeallocate(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return Objects.hash(name);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
Deallocate o = (Deallocate) obj;
return Objects.equals(name, o.name);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.toString();
}
}
@@ -1,82 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import java.util.Objects;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class DecimalLiteral
extends Literal
{
private final String value;
public DecimalLiteral(String value)
{
this(Optional.empty(), value);
}
public DecimalLiteral(NodeLocation location, String value)
{
this(Optional.of(location), value);
}
public DecimalLiteral(Optional<NodeLocation> location, String value)
{
super(location);
this.value = requireNonNull(value, "value is null");
}
public String getValue()
{
return value;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDecimalLiteral(this, context);
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DecimalLiteral that = (DecimalLiteral) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode()
{
return Objects.hash(value);
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
DecimalLiteral otherLiteral = (DecimalLiteral) other;
return value.equals(otherLiteral.value);
}
}
@@ -1,97 +0,0 @@
/*
* Copyright (C) Canner, Inc - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Written by Canner dev team <contact@cannerdata.com>, Sep 2022
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import io.trino.sql.SqlFormatter;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class Declare
extends Statement
{
private final Identifier name;
private final Query body;
public Declare(NodeLocation location, Identifier name, Query body)
{
this(Optional.of(location), name, body);
}
public Declare(Identifier name, Query body)
{
this(Optional.empty(), name, body);
}
protected Declare(Optional<NodeLocation> location, Identifier name, Query body)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.body = requireNonNull(body, "body is null");
}
public Identifier getName()
{
return name;
}
public Query getBody()
{
return body;
}
public String toStatement()
{
return SqlFormatter.formatSql(body);
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDeclareCursor(this, context);
}
@Override
public List<? extends Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return Objects.hash(name, body);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
Declare o = (Declare) obj;
return Objects.equals(name, o.name)
&& Objects.equals(body, o.body);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("body", body)
.toString();
}
}
@@ -1,28 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
/**
* When walking Expressions, don't traverse into SubqueryExpressions
*/
public abstract class DefaultExpressionTraversalVisitor<C>
extends DefaultTraversalVisitor<C>
{
@Override
protected Void visitSubqueryExpression(SubqueryExpression node, C context)
{
// Don't traverse into Subqueries within an Expression
return null;
}
}
@@ -1,914 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
public abstract class DefaultTraversalVisitor<C>
extends AstVisitor<Void, C>
{
@Override
protected Void visitExtract(Extract node, C context)
{
process(node.getExpression(), context);
return null;
}
@Override
protected Void visitCast(Cast node, C context)
{
process(node.getExpression(), context);
return null;
}
@Override
protected Void visitArithmeticBinary(ArithmeticBinaryExpression node, C context)
{
process(node.getLeft(), context);
process(node.getRight(), context);
return null;
}
@Override
protected Void visitBetweenPredicate(BetweenPredicate node, C context)
{
process(node.getValue(), context);
process(node.getMin(), context);
process(node.getMax(), context);
return null;
}
@Override
protected Void visitCoalesceExpression(CoalesceExpression node, C context)
{
for (Expression operand : node.getOperands()) {
process(operand, context);
}
return null;
}
@Override
protected Void visitAtTimeZone(AtTimeZone node, C context)
{
process(node.getValue(), context);
process(node.getTimeZone(), context);
return null;
}
@Override
protected Void visitArrayConstructor(ArrayConstructor node, C context)
{
for (Expression expression : node.getValues()) {
process(expression, context);
}
return null;
}
@Override
protected Void visitSubscriptExpression(SubscriptExpression node, C context)
{
process(node.getBase(), context);
process(node.getIndex(), context);
return null;
}
@Override
protected Void visitComparisonExpression(ComparisonExpression node, C context)
{
process(node.getLeft(), context);
process(node.getRight(), context);
return null;
}
@Override
protected Void visitFormat(Format node, C context)
{
for (Expression argument : node.getArguments()) {
process(argument, context);
}
return null;
}
@Override
protected Void visitQuery(Query node, C context)
{
if (node.getWith().isPresent()) {
process(node.getWith().get(), context);
}
process(node.getQueryBody(), context);
if (node.getOrderBy().isPresent()) {
process(node.getOrderBy().get(), context);
}
if (node.getOffset().isPresent()) {
process(node.getOffset().get(), context);
}
if (node.getLimit().isPresent()) {
process(node.getLimit().get(), context);
}
return null;
}
@Override
protected Void visitWith(With node, C context)
{
for (WithQuery query : node.getQueries()) {
process(query, context);
}
return null;
}
@Override
protected Void visitWithQuery(WithQuery node, C context)
{
process(node.getQuery(), context);
return null;
}
@Override
protected Void visitSelect(Select node, C context)
{
for (SelectItem item : node.getSelectItems()) {
process(item, context);
}
return null;
}
@Override
protected Void visitSingleColumn(SingleColumn node, C context)
{
process(node.getExpression(), context);
return null;
}
@Override
protected Void visitAllColumns(AllColumns node, C context)
{
node.getTarget().ifPresent(value -> process(value, context));
return null;
}
@Override
protected Void visitWhenClause(WhenClause node, C context)
{
process(node.getOperand(), context);
process(node.getResult(), context);
return null;
}
@Override
protected Void visitInPredicate(InPredicate node, C context)
{
process(node.getValue(), context);
process(node.getValueList(), context);
return null;
}
@Override
protected Void visitFunctionCall(FunctionCall node, C context)
{
for (Expression argument : node.getArguments()) {
process(argument, context);
}
if (node.getOrderBy().isPresent()) {
process(node.getOrderBy().get(), context);
}
if (node.getWindow().isPresent()) {
process((Node) node.getWindow().get(), context);
}
if (node.getFilter().isPresent()) {
process(node.getFilter().get(), context);
}
return null;
}
@Override
protected Void visitWindowOperation(WindowOperation node, C context)
{
process(node.getName(), context);
process((Node) node.getWindow(), context);
return null;
}
@Override
protected Void visitGroupingOperation(GroupingOperation node, C context)
{
for (Expression columnArgument : node.getGroupingColumns()) {
process(columnArgument, context);
}
return null;
}
@Override
protected Void visitDereferenceExpression(DereferenceExpression node, C context)
{
process(node.getBase(), context);
return null;
}
@Override
protected Void visitWindowReference(WindowReference node, C context)
{
process(node.getName(), context);
return null;
}
@Override
public Void visitWindowSpecification(WindowSpecification node, C context)
{
if (node.getExistingWindowName().isPresent()) {
process(node.getExistingWindowName().get(), context);
}
for (Expression expression : node.getPartitionBy()) {
process(expression, context);
}
if (node.getOrderBy().isPresent()) {
process(node.getOrderBy().get(), context);
}
if (node.getFrame().isPresent()) {
process(node.getFrame().get(), context);
}
return null;
}
@Override
protected Void visitWindowDefinition(WindowDefinition node, C context)
{
process(node.getWindow());
return null;
}
@Override
public Void visitWindowFrame(WindowFrame node, C context)
{
process(node.getStart(), context);
if (node.getEnd().isPresent()) {
process(node.getEnd().get(), context);
}
for (MeasureDefinition measureDefinition : node.getMeasures()) {
process(measureDefinition, context);
}
for (VariableDefinition variableDefinition : node.getVariableDefinitions()) {
process(variableDefinition, context);
}
return null;
}
@Override
protected Void visitMeasureDefinition(MeasureDefinition node, C context)
{
process(node.getExpression(), context);
return null;
}
@Override
protected Void visitVariableDefinition(VariableDefinition node, C context)
{
process(node.getExpression(), context);
return null;
}
@Override
public Void visitFrameBound(FrameBound node, C context)
{
if (node.getValue().isPresent()) {
process(node.getValue().get(), context);
}
return null;
}
@Override
protected Void visitOffset(Offset node, C context)
{
process(node.getRowCount());
return null;
}
@Override
protected Void visitLimit(Limit node, C context)
{
process(node.getRowCount());
return null;
}
@Override
protected Void visitFetchFirst(FetchFirst node, C context)
{
node.getRowCount().ifPresent(this::process);
return null;
}
@Override
protected Void visitSimpleCaseExpression(SimpleCaseExpression node, C context)
{
process(node.getOperand(), context);
for (WhenClause clause : node.getWhenClauses()) {
process(clause, context);
}
node.getDefaultValue()
.ifPresent(value -> process(value, context));
return null;
}
@Override
protected Void visitInListExpression(InListExpression node, C context)
{
for (Expression value : node.getValues()) {
process(value, context);
}
return null;
}
@Override
protected Void visitNullIfExpression(NullIfExpression node, C context)
{
process(node.getFirst(), context);
process(node.getSecond(), context);
return null;
}
@Override
protected Void visitIfExpression(IfExpression node, C context)
{
process(node.getCondition(), context);
process(node.getTrueValue(), context);
if (node.getFalseValue().isPresent()) {
process(node.getFalseValue().get(), context);
}
return null;
}
@Override
protected Void visitTryExpression(TryExpression node, C context)
{
process(node.getInnerExpression(), context);
return null;
}
@Override
protected Void visitBindExpression(BindExpression node, C context)
{
for (Expression value : node.getValues()) {
process(value, context);
}
process(node.getFunction(), context);
return null;
}
@Override
protected Void visitArithmeticUnary(ArithmeticUnaryExpression node, C context)
{
process(node.getValue(), context);
return null;
}
@Override
protected Void visitNotExpression(NotExpression node, C context)
{
process(node.getValue(), context);
return null;
}
@Override
protected Void visitSearchedCaseExpression(SearchedCaseExpression node, C context)
{
for (WhenClause clause : node.getWhenClauses()) {
process(clause, context);
}
node.getDefaultValue()
.ifPresent(value -> process(value, context));
return null;
}
@Override
protected Void visitLikePredicate(LikePredicate node, C context)
{
process(node.getValue(), context);
process(node.getPattern(), context);
node.getEscape().ifPresent(value -> process(value, context));
return null;
}
@Override
protected Void visitIsNotNullPredicate(IsNotNullPredicate node, C context)
{
process(node.getValue(), context);
return null;
}
@Override
protected Void visitIsNullPredicate(IsNullPredicate node, C context)
{
process(node.getValue(), context);
return null;
}
@Override
protected Void visitLogicalExpression(LogicalExpression node, C context)
{
for (Node child : node.getTerms()) {
process(child, context);
}
return null;
}
@Override
protected Void visitSubqueryExpression(SubqueryExpression node, C context)
{
process(node.getQuery(), context);
return null;
}
@Override
protected Void visitOrderBy(OrderBy node, C context)
{
for (SortItem sortItem : node.getSortItems()) {
process(sortItem, context);
}
return null;
}
@Override
protected Void visitSortItem(SortItem node, C context)
{
process(node.getSortKey(), context);
return null;
}
@Override
protected Void visitQuerySpecification(QuerySpecification node, C context)
{
process(node.getSelect(), context);
if (node.getFrom().isPresent()) {
process(node.getFrom().get(), context);
}
if (node.getWhere().isPresent()) {
process(node.getWhere().get(), context);
}
if (node.getGroupBy().isPresent()) {
process(node.getGroupBy().get(), context);
}
if (node.getHaving().isPresent()) {
process(node.getHaving().get(), context);
}
for (WindowDefinition windowDefinition : node.getWindows()) {
process(windowDefinition, context);
}
if (node.getOrderBy().isPresent()) {
process(node.getOrderBy().get(), context);
}
if (node.getOffset().isPresent()) {
process(node.getOffset().get(), context);
}
if (node.getLimit().isPresent()) {
process(node.getLimit().get(), context);
}
return null;
}
@Override
protected Void visitSetOperation(SetOperation node, C context)
{
for (Relation relation : node.getRelations()) {
process(relation, context);
}
return null;
}
@Override
protected Void visitValues(Values node, C context)
{
for (Expression row : node.getRows()) {
process(row, context);
}
return null;
}
@Override
protected Void visitRow(Row node, C context)
{
for (Expression expression : node.getItems()) {
process(expression, context);
}
return null;
}
@Override
protected Void visitTableSubquery(TableSubquery node, C context)
{
process(node.getQuery(), context);
return null;
}
@Override
protected Void visitAliasedRelation(AliasedRelation node, C context)
{
process(node.getRelation(), context);
return null;
}
@Override
protected Void visitSampledRelation(SampledRelation node, C context)
{
process(node.getRelation(), context);
process(node.getSamplePercentage(), context);
return null;
}
@Override
protected Void visitJoin(Join node, C context)
{
process(node.getLeft(), context);
process(node.getRight(), context);
node.getCriteria()
.filter(criteria -> criteria instanceof JoinOn)
.ifPresent(criteria -> process(((JoinOn) criteria).getExpression(), context));
return null;
}
@Override
protected Void visitUnnest(Unnest node, C context)
{
for (Expression expression : node.getExpressions()) {
process(expression, context);
}
return null;
}
@Override
protected Void visitGroupBy(GroupBy node, C context)
{
for (GroupingElement groupingElement : node.getGroupingElements()) {
process(groupingElement, context);
}
return null;
}
@Override
protected Void visitCube(Cube node, C context)
{
return null;
}
@Override
protected Void visitRollup(Rollup node, C context)
{
return null;
}
@Override
protected Void visitSimpleGroupBy(SimpleGroupBy node, C context)
{
for (Expression expression : node.getExpressions()) {
process(expression, context);
}
return null;
}
@Override
protected Void visitGroupingSets(GroupingSets node, C context)
{
return null;
}
@Override
protected Void visitInsert(Insert node, C context)
{
process(node.getQuery(), context);
return null;
}
@Override
protected Void visitRefreshMaterializedView(RefreshMaterializedView node, C context)
{
return null;
}
@Override
protected Void visitDelete(Delete node, C context)
{
process(node.getTable(), context);
node.getWhere().ifPresent(where -> process(where, context));
return null;
}
@Override
protected Void visitUpdate(Update node, C context)
{
process(node.getTable(), context);
node.getAssignments().forEach(value -> process(value, context));
node.getWhere().ifPresent(where -> process(where, context));
return null;
}
@Override
protected Void visitUpdateAssignment(UpdateAssignment node, C context)
{
process(node.getName(), context);
process(node.getValue(), context);
return null;
}
@Override
protected Void visitMerge(Merge node, C context)
{
process(node.getTable(), context);
node.getTargetAlias().ifPresent(target -> process(target, context));
process(node.getRelation(), context);
process(node.getExpression(), context);
node.getMergeCases().forEach(mergeCase -> process(mergeCase, context));
return null;
}
@Override
protected Void visitMergeInsert(MergeInsert node, C context)
{
node.getExpression().ifPresent(expression -> process(expression, context));
node.getColumns().forEach(column -> process(column, context));
node.getValues().forEach(expression -> process(expression, context));
return null;
}
@Override
protected Void visitMergeUpdate(MergeUpdate node, C context)
{
node.getExpression().ifPresent(expression -> process(expression, context));
node.getAssignments().forEach(assignment -> {
process(assignment.getTarget(), context);
process(assignment.getValue(), context);
});
return null;
}
@Override
protected Void visitMergeDelete(MergeDelete node, C context)
{
node.getExpression().ifPresent(expression -> process(expression, context));
return null;
}
@Override
protected Void visitCreateTableAsSelect(CreateTableAsSelect node, C context)
{
process(node.getQuery(), context);
for (Property property : node.getProperties()) {
process(property, context);
}
return null;
}
@Override
protected Void visitProperty(Property node, C context)
{
process(node.getName(), context);
if (!node.isSetToDefault()) {
process(node.getNonDefaultValue(), context);
}
return null;
}
@Override
protected Void visitAnalyze(Analyze node, C context)
{
for (Property property : node.getProperties()) {
process(property, context);
}
return null;
}
@Override
protected Void visitCreateView(CreateView node, C context)
{
process(node.getQuery(), context);
return null;
}
@Override
protected Void visitSetSession(SetSession node, C context)
{
process(node.getValue(), context);
return null;
}
@Override
protected Void visitAddColumn(AddColumn node, C context)
{
process(node.getColumn(), context);
return null;
}
@Override
protected Void visitCreateSchema(CreateSchema node, C context)
{
for (Property property : node.getProperties()) {
process(property, context);
}
return null;
}
@Override
protected Void visitCreateTable(CreateTable node, C context)
{
for (TableElement tableElement : node.getElements()) {
process(tableElement, context);
}
for (Property property : node.getProperties()) {
process(property, context);
}
return null;
}
@Override
protected Void visitStartTransaction(StartTransaction node, C context)
{
for (TransactionMode transactionMode : node.getTransactionModes()) {
process(transactionMode, context);
}
return null;
}
@Override
protected Void visitExplain(Explain node, C context)
{
process(node.getStatement(), context);
for (ExplainOption option : node.getOptions()) {
process(option, context);
}
return null;
}
@Override
protected Void visitExplainAnalyze(ExplainAnalyze node, C context)
{
process(node.getStatement(), context);
return null;
}
@Override
protected Void visitShowStats(ShowStats node, C context)
{
process(node.getRelation(), context);
return null;
}
@Override
protected Void visitQuantifiedComparisonExpression(QuantifiedComparisonExpression node, C context)
{
process(node.getValue(), context);
process(node.getSubquery(), context);
return null;
}
@Override
protected Void visitExists(ExistsPredicate node, C context)
{
process(node.getSubquery(), context);
return null;
}
@Override
protected Void visitLateral(Lateral node, C context)
{
process(node.getQuery(), context);
return null;
}
@Override
protected Void visitLambdaExpression(LambdaExpression node, C context)
{
process(node.getBody(), context);
return null;
}
@Override
protected Void visitExcludedPattern(ExcludedPattern node, C context)
{
process(node.getPattern(), context);
return null;
}
@Override
protected Void visitPatternAlternation(PatternAlternation node, C context)
{
for (RowPattern rowPattern : node.getPatterns()) {
process(rowPattern, context);
}
return null;
}
@Override
protected Void visitPatternConcatenation(PatternConcatenation node, C context)
{
for (RowPattern rowPattern : node.getPatterns()) {
process(rowPattern, context);
}
return null;
}
@Override
protected Void visitPatternPermutation(PatternPermutation node, C context)
{
for (RowPattern rowPattern : node.getPatterns()) {
process(rowPattern, context);
}
return null;
}
@Override
protected Void visitPatternVariable(PatternVariable node, C context)
{
process(node.getName(), context);
return null;
}
@Override
protected Void visitQuantifiedPattern(QuantifiedPattern node, C context)
{
process(node.getPattern(), context);
return null;
}
@Override
protected Void visitLabelDereference(LabelDereference node, C context)
{
node.getReference().ifPresent(reference -> process(reference, context));
return null;
}
}
@@ -1,101 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class Delete
extends Statement
{
private final Table table;
private final Optional<Expression> where;
public Delete(Table table, Optional<Expression> where)
{
this(Optional.empty(), table, where);
}
public Delete(NodeLocation location, Table table, Optional<Expression> where)
{
this(Optional.of(location), table, where);
}
private Delete(Optional<NodeLocation> location, Table table, Optional<Expression> where)
{
super(location);
this.table = requireNonNull(table, "table is null");
this.where = requireNonNull(where, "where is null");
}
public Table getTable()
{
return table;
}
public Optional<Expression> getWhere()
{
return where;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDelete(this, context);
}
@Override
public List<Node> getChildren()
{
ImmutableList.Builder<Node> nodes = ImmutableList.builder();
nodes.add(table);
where.ifPresent(nodes::add);
return nodes.build();
}
@Override
public int hashCode()
{
return Objects.hash(table, where);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
Delete o = (Delete) obj;
return Objects.equals(table, o.table) &&
Objects.equals(where, o.where);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("table", table.getName())
.add("where", where)
.toString();
}
}
@@ -1,117 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class Deny
extends Statement
{
private final Optional<List<String>> privileges; // missing means ALL PRIVILEGES
private final Optional<GrantOnType> type;
private final QualifiedName name;
private final PrincipalSpecification grantee;
public Deny(Optional<List<String>> privileges, Optional<GrantOnType> type, QualifiedName name, PrincipalSpecification grantee)
{
this(Optional.empty(), privileges, type, name, grantee);
}
public Deny(NodeLocation location, Optional<List<String>> privileges, Optional<GrantOnType> type, QualifiedName name, PrincipalSpecification grantee)
{
this(Optional.of(location), privileges, type, name, grantee);
}
private Deny(Optional<NodeLocation> location, Optional<List<String>> privileges, Optional<GrantOnType> type, QualifiedName name, PrincipalSpecification grantee)
{
super(location);
requireNonNull(privileges, "privileges is null");
this.privileges = privileges.map(ImmutableList::copyOf);
this.type = requireNonNull(type, "type is null");
this.name = requireNonNull(name, "name is null");
this.grantee = requireNonNull(grantee, "grantee is null");
}
public Optional<List<String>> getPrivileges()
{
return privileges;
}
public Optional<GrantOnType> getType()
{
return type;
}
public QualifiedName getName()
{
return name;
}
public PrincipalSpecification getGrantee()
{
return grantee;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDeny(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return Objects.hash(privileges, type, name, grantee);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Deny o = (Deny) obj;
return Objects.equals(privileges, o.privileges) &&
Objects.equals(type, o.type) &&
Objects.equals(name, o.name) &&
Objects.equals(grantee, o.grantee);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("privileges", privileges)
.add("type", type)
.add("name", name)
.add("grantee", grantee)
.toString();
}
}
@@ -1,160 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
public class DereferenceExpression
extends Expression
{
private final Expression base;
private final Optional<Identifier> field;
public DereferenceExpression(Expression base, Identifier field)
{
this(Optional.empty(), base, Optional.of(field));
}
public DereferenceExpression(NodeLocation location, Expression base, Identifier field)
{
this(Optional.of(location), base, Optional.of(field));
}
public DereferenceExpression(Identifier label)
{
this(Optional.empty(), label, Optional.empty());
}
public DereferenceExpression(NodeLocation location, Identifier label)
{
this(Optional.of(location), label, Optional.empty());
}
public DereferenceExpression(Optional<NodeLocation> location, Expression base, Optional<Identifier> field)
{
super(location);
checkArgument(base != null, "base is null");
requireNonNull(field, "field is null");
this.base = base;
this.field = field;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDereferenceExpression(this, context);
}
@Override
public List<Node> getChildren()
{
ImmutableList.Builder<Node> children = ImmutableList.builder();
children.add(base);
field.ifPresent(children::add);
return children.build();
}
public Expression getBase()
{
return base;
}
public Optional<Identifier> getField()
{
return field;
}
/**
* If this DereferenceExpression looks like a QualifiedName, return QualifiedName.
* Otherwise return null
*/
public static QualifiedName getQualifiedName(DereferenceExpression expression)
{
if (!expression.field.isPresent()) {
return null;
}
Identifier field = expression.field.get();
List<Identifier> parts = null;
if (expression.base instanceof Identifier) {
parts = ImmutableList.of((Identifier) expression.base, field);
}
else if (expression.base instanceof DereferenceExpression) {
QualifiedName baseQualifiedName = getQualifiedName((DereferenceExpression) expression.base);
if (baseQualifiedName != null) {
ImmutableList.Builder<Identifier> builder = ImmutableList.builder();
builder.addAll(baseQualifiedName.getOriginalParts());
builder.add(field);
parts = builder.build();
}
}
return parts == null ? null : QualifiedName.of(parts);
}
public static Expression from(QualifiedName name)
{
Expression result = null;
for (Identifier part : name.getOriginalParts()) {
if (result == null) {
result = part;
}
else {
result = new DereferenceExpression(result, part);
}
}
return result;
}
public static boolean isQualifiedAllFieldsReference(Expression expression)
{
return expression instanceof DereferenceExpression && !((DereferenceExpression) expression).field.isPresent();
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DereferenceExpression that = (DereferenceExpression) o;
return Objects.equals(base, that.base) &&
Objects.equals(field, that.field);
}
@Override
public int hashCode()
{
return Objects.hash(base, field);
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,88 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
public class DescribeInput
extends Statement
{
private final Identifier name;
public DescribeInput(NodeLocation location, Identifier name)
{
this(Optional.of(location), name);
}
public DescribeInput(Identifier name)
{
this(Optional.empty(), name);
}
private DescribeInput(Optional<NodeLocation> location, Identifier name)
{
super(location);
this.name = name;
}
public Identifier getName()
{
return name;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDescribeInput(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return Objects.hash(name);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
DescribeInput o = (DescribeInput) obj;
return Objects.equals(name, o.name);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.toString();
}
}
@@ -1,88 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
public class DescribeOutput
extends Statement
{
private final Identifier name;
public DescribeOutput(NodeLocation location, Identifier name)
{
this(Optional.of(location), name);
}
public DescribeOutput(Identifier name)
{
this(Optional.empty(), name);
}
private DescribeOutput(Optional<NodeLocation> location, Identifier name)
{
super(location);
this.name = name;
}
public Identifier getName()
{
return name;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDescribeOutput(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return Objects.hash(name);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
DescribeOutput o = (DescribeOutput) obj;
return Objects.equals(name, o.name);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.toString();
}
}
@@ -1,89 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class DoubleLiteral
extends Literal
{
private final double value;
public DoubleLiteral(String value)
{
this(Optional.empty(), value);
}
public DoubleLiteral(NodeLocation location, String value)
{
this(Optional.of(location), value);
}
private DoubleLiteral(Optional<NodeLocation> location, String value)
{
super(location);
requireNonNull(value, "value is null");
this.value = Double.parseDouble(value);
}
public double getValue()
{
return value;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDoubleLiteral(this, context);
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DoubleLiteral that = (DoubleLiteral) o;
if (Double.compare(that.value, value) != 0) {
return false;
}
return true;
}
@SuppressWarnings("UnaryPlus")
@Override
public int hashCode()
{
long temp = value != +0.0d ? Double.doubleToLongBits(value) : 0L;
return (int) (temp ^ (temp >>> 32));
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
return value == ((DoubleLiteral) other).value;
}
}
@@ -1,112 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class DropColumn
extends Statement
{
private final QualifiedName table;
private final Identifier column;
private final boolean tableExists;
private final boolean columnExists;
public DropColumn(QualifiedName table, Identifier column, boolean tableExists, boolean columnExists)
{
this(Optional.empty(), table, column, tableExists, columnExists);
}
public DropColumn(NodeLocation location, QualifiedName table, Identifier column, boolean tableExists, boolean columnExists)
{
this(Optional.of(location), table, column, tableExists, columnExists);
}
private DropColumn(Optional<NodeLocation> location, QualifiedName table, Identifier column, boolean tableExists, boolean columnExists)
{
super(location);
this.table = requireNonNull(table, "table is null");
this.column = requireNonNull(column, "column is null");
this.tableExists = tableExists;
this.columnExists = columnExists;
}
public QualifiedName getTable()
{
return table;
}
public Identifier getColumn()
{
return column;
}
public boolean isTableExists()
{
return tableExists;
}
public boolean isColumnExists()
{
return columnExists;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDropColumn(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DropColumn that = (DropColumn) o;
return Objects.equals(table, that.table) &&
Objects.equals(column, that.column);
}
@Override
public int hashCode()
{
return Objects.hash(table, column);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("table", table)
.add("column", column)
.toString();
}
}
@@ -1,97 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
public class DropMaterializedView
extends Statement
{
private final QualifiedName name;
private final boolean exists;
public DropMaterializedView(QualifiedName name, boolean exists)
{
this(Optional.empty(), name, exists);
}
public DropMaterializedView(NodeLocation location, QualifiedName name, boolean exists)
{
this(Optional.of(location), name, exists);
}
private DropMaterializedView(Optional<NodeLocation> location, QualifiedName name, boolean exists)
{
super(location);
this.name = name;
this.exists = exists;
}
public QualifiedName getName()
{
return name;
}
public boolean isExists()
{
return exists;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDropMaterializedView(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return Objects.hash(name, exists);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
DropMaterializedView o = (DropMaterializedView) obj;
return Objects.equals(name, o.name)
&& (exists == o.exists);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("exists", exists)
.toString();
}
}
@@ -1,98 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class DropRole
extends Statement
{
private final Identifier name;
private final Optional<Identifier> catalog;
public DropRole(Identifier name, Optional<Identifier> catalog)
{
this(Optional.empty(), name, catalog);
}
public DropRole(NodeLocation location, Identifier name, Optional<Identifier> catalog)
{
this(Optional.of(location), name, catalog);
}
private DropRole(Optional<NodeLocation> location, Identifier name, Optional<Identifier> catalog)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.catalog = requireNonNull(catalog, "catalog is null");
}
public Identifier getName()
{
return name;
}
public Optional<Identifier> getCatalog()
{
return catalog;
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DropRole dropRole = (DropRole) o;
return Objects.equals(name, dropRole.name) &&
Objects.equals(catalog, dropRole.catalog);
}
@Override
public int hashCode()
{
return Objects.hash(name, catalog);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("catalog", catalog)
.toString();
}
@Override
public List<? extends Node> getChildren()
{
return ImmutableList.of();
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDropRole(this, context);
}
}
@@ -1,107 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public final class DropSchema
extends Statement
{
private final QualifiedName schemaName;
private final boolean exists;
private final boolean cascade;
public DropSchema(QualifiedName schemaName, boolean exists, boolean cascade)
{
this(Optional.empty(), schemaName, exists, cascade);
}
public DropSchema(NodeLocation location, QualifiedName schemaName, boolean exists, boolean cascade)
{
this(Optional.of(location), schemaName, exists, cascade);
}
private DropSchema(Optional<NodeLocation> location, QualifiedName schemaName, boolean exists, boolean cascade)
{
super(location);
this.schemaName = requireNonNull(schemaName, "schemaName is null");
this.exists = exists;
this.cascade = cascade;
}
public QualifiedName getSchemaName()
{
return schemaName;
}
public boolean isExists()
{
return exists;
}
public boolean isCascade()
{
return cascade;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDropSchema(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
DropSchema o = (DropSchema) obj;
return Objects.equals(schemaName, o.schemaName) &&
(exists == o.exists) &&
(cascade == o.cascade);
}
@Override
public int hashCode()
{
return Objects.hash(schemaName, exists);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("schemaName", schemaName)
.add("exists", exists)
.add("cascade", cascade)
.toString();
}
}
@@ -1,97 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
public class DropTable
extends Statement
{
private final QualifiedName tableName;
private final boolean exists;
public DropTable(QualifiedName tableName, boolean exists)
{
this(Optional.empty(), tableName, exists);
}
public DropTable(NodeLocation location, QualifiedName tableName, boolean exists)
{
this(Optional.of(location), tableName, exists);
}
private DropTable(Optional<NodeLocation> location, QualifiedName tableName, boolean exists)
{
super(location);
this.tableName = tableName;
this.exists = exists;
}
public QualifiedName getTableName()
{
return tableName;
}
public boolean isExists()
{
return exists;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDropTable(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return Objects.hash(tableName, exists);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
DropTable o = (DropTable) obj;
return Objects.equals(tableName, o.tableName)
&& (exists == o.exists);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("tableName", tableName)
.add("exists", exists)
.toString();
}
}
@@ -1,97 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
public class DropView
extends Statement
{
private final QualifiedName name;
private final boolean exists;
public DropView(QualifiedName name, boolean exists)
{
this(Optional.empty(), name, exists);
}
public DropView(NodeLocation location, QualifiedName name, boolean exists)
{
this(Optional.of(location), name, exists);
}
private DropView(Optional<NodeLocation> location, QualifiedName name, boolean exists)
{
super(location);
this.name = name;
this.exists = exists;
}
public QualifiedName getName()
{
return name;
}
public boolean isExists()
{
return exists;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitDropView(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return Objects.hash(name, exists);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
DropView o = (DropView) obj;
return Objects.equals(name, o.name)
&& (exists == o.exists);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("exists", exists)
.toString();
}
}
@@ -1,78 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
public class EmptyPattern
extends RowPattern
{
public EmptyPattern(NodeLocation location)
{
this(Optional.of(location));
}
private EmptyPattern(Optional<NodeLocation> location)
{
super(location);
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitEmptyPattern(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
return true;
}
@Override
public int hashCode()
{
return getClass().hashCode();
}
@Override
public String toString()
{
return toStringHelper(this)
.toString();
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,119 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class Except
extends SetOperation
{
private final Relation left;
private final Relation right;
public Except(Relation left, Relation right, boolean distinct)
{
this(Optional.empty(), left, right, distinct);
}
public Except(NodeLocation location, Relation left, Relation right, boolean distinct)
{
this(Optional.of(location), left, right, distinct);
}
private Except(Optional<NodeLocation> location, Relation left, Relation right, boolean distinct)
{
super(location, distinct);
requireNonNull(left, "left is null");
requireNonNull(right, "right is null");
this.left = left;
this.right = right;
}
public Relation getLeft()
{
return left;
}
public Relation getRight()
{
return right;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitExcept(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(left, right);
}
@Override
public List<Relation> getRelations()
{
return ImmutableList.of(left, right);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("left", left)
.add("right", right)
.add("distinct", isDistinct())
.toString();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
Except o = (Except) obj;
return Objects.equals(left, o.left) &&
Objects.equals(right, o.right) &&
Objects.equals(isDistinct(), o.isDistinct());
}
@Override
public int hashCode()
{
return Objects.hash(left, right, isDistinct());
}
@Override
public boolean shallowEquals(Node other)
{
if (!sameClass(this, other)) {
return false;
}
return this.isDistinct() == ((Except) other).isDistinct();
}
}
@@ -1,90 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class ExcludedPattern
extends RowPattern
{
private final RowPattern pattern;
public ExcludedPattern(NodeLocation location, RowPattern pattern)
{
this(Optional.of(location), pattern);
}
private ExcludedPattern(Optional<NodeLocation> location, RowPattern pattern)
{
super(location);
this.pattern = requireNonNull(pattern, "pattern is null");
}
public RowPattern getPattern()
{
return pattern;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitExcludedPattern(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(pattern);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
ExcludedPattern o = (ExcludedPattern) obj;
return Objects.equals(pattern, o.pattern);
}
@Override
public int hashCode()
{
return Objects.hash(pattern);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("pattern", pattern)
.toString();
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,98 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class Execute
extends Statement
{
private final Identifier name;
private final List<Expression> parameters;
public Execute(NodeLocation location, Identifier name, List<Expression> parameters)
{
this(Optional.of(location), name, parameters);
}
public Execute(Identifier name, List<Expression> parameters)
{
this(Optional.empty(), name, parameters);
}
private Execute(Optional<NodeLocation> location, Identifier name, List<Expression> parameters)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.parameters = ImmutableList.copyOf(requireNonNull(parameters, "parameters is null"));
}
public Identifier getName()
{
return name;
}
public List<Expression> getParameters()
{
return parameters;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitExecute(this, context);
}
@Override
public List<? extends Node> getChildren()
{
return parameters;
}
@Override
public int hashCode()
{
return Objects.hash(name, parameters);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
Execute o = (Execute) obj;
return Objects.equals(name, o.name) &&
Objects.equals(parameters, o.parameters);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("parameters", parameters)
.toString();
}
}
@@ -1,88 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class ExistsPredicate
extends Expression
{
private final Expression subquery;
public ExistsPredicate(Expression subquery)
{
this(Optional.empty(), subquery);
}
public ExistsPredicate(NodeLocation location, Expression subquery)
{
this(Optional.of(location), subquery);
}
private ExistsPredicate(Optional<NodeLocation> location, Expression subquery)
{
super(location);
requireNonNull(subquery, "subquery is null");
this.subquery = subquery;
}
public Expression getSubquery()
{
return subquery;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitExists(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of(subquery);
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ExistsPredicate that = (ExistsPredicate) o;
return Objects.equals(subquery, that.subquery);
}
@Override
public int hashCode()
{
return subquery.hashCode();
}
@Override
public boolean shallowEquals(Node other)
{
return sameClass(this, other);
}
}
@@ -1,101 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public final class Explain
extends Statement
{
private final Statement statement;
private final List<ExplainOption> options;
public Explain(Statement statement, List<ExplainOption> options)
{
this(Optional.empty(), statement, options);
}
public Explain(NodeLocation location, Statement statement, List<ExplainOption> options)
{
this(Optional.of(location), statement, options);
}
public Explain(Optional<NodeLocation> location, Statement statement, List<ExplainOption> options)
{
super(location);
this.statement = requireNonNull(statement, "statement is null");
this.options = ImmutableList.copyOf(requireNonNull(options, "options is null"));
}
public Statement getStatement()
{
return statement;
}
public List<ExplainOption> getOptions()
{
return options;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitExplain(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.<Node>builder()
.add(statement)
.addAll(options)
.build();
}
@Override
public int hashCode()
{
return Objects.hash(statement, options);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
Explain o = (Explain) obj;
return Objects.equals(statement, o.statement) &&
Objects.equals(options, o.options);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("statement", statement)
.add("options", options)
.toString();
}
}
@@ -1,99 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public final class ExplainAnalyze
extends Statement
{
private final Statement statement;
private final boolean verbose;
public ExplainAnalyze(Statement statement, boolean verbose)
{
this(Optional.empty(), statement, verbose);
}
public ExplainAnalyze(NodeLocation location, boolean verbose, Statement statement)
{
this(Optional.of(location), statement, verbose);
}
public ExplainAnalyze(Optional<NodeLocation> location, Statement statement, boolean verbose)
{
super(location);
this.statement = requireNonNull(statement, "statement is null");
this.verbose = verbose;
}
public Statement getStatement()
{
return statement;
}
public boolean isVerbose()
{
return verbose;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitExplainAnalyze(this, context);
}
@Override
public List<Node> getChildren()
{
return ImmutableList.<Node>builder()
.add(statement)
.build();
}
@Override
public int hashCode()
{
return Objects.hash(statement, verbose);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
ExplainAnalyze o = (ExplainAnalyze) obj;
return Objects.equals(statement, o.statement);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("statement", statement)
.add("verbose", verbose)
.toString();
}
}
@@ -1,90 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class ExplainFormat
extends ExplainOption
{
public enum Type
{
TEXT,
GRAPHVIZ,
JSON
}
private final Type type;
public ExplainFormat(Type type)
{
this(Optional.empty(), type);
}
public ExplainFormat(NodeLocation location, Type type)
{
this(Optional.of(location), type);
}
private ExplainFormat(Optional<NodeLocation> location, Type type)
{
super(location);
this.type = requireNonNull(type, "type is null");
}
public Type getType()
{
return type;
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return Objects.hash(type);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
ExplainFormat o = (ExplainFormat) obj;
return type == o.type;
}
@Override
public String toString()
{
return toStringHelper(this)
.add("type", type)
.toString();
}
}
@@ -1,31 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import java.util.Optional;
public abstract class ExplainOption
extends Node
{
protected ExplainOption(Optional<NodeLocation> location)
{
super(location);
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{
return visitor.visitExplainOption(this, context);
}
}
@@ -1,91 +0,0 @@
/*
* Licensed 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.
*/
package io.trino.sql.tree;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
public class ExplainType
extends ExplainOption
{
public enum Type
{
LOGICAL,
DISTRIBUTED,
VALIDATE,
IO
}
private final Type type;
public ExplainType(Type type)
{
this(Optional.empty(), type);
}
public ExplainType(NodeLocation location, Type type)
{
this(Optional.of(location), type);
}
private ExplainType(Optional<NodeLocation> location, Type type)
{
super(location);
this.type = requireNonNull(type, "type is null");
}
public Type getType()
{
return type;
}
@Override
public List<Node> getChildren()
{
return ImmutableList.of();
}
@Override
public int hashCode()
{
return Objects.hash(type);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}
ExplainType o = (ExplainType) obj;
return type == o.type;
}
@Override
public String toString()
{
return toStringHelper(this)
.add("type", type)
.toString();
}
}

Some files were not shown because too many files have changed in this diff Show More