Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions phoenix-core/pom.xml
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,6 +89,53 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-fmpp-resources</id>
<phase>initialize</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/codegen</outputDirectory>
<resources>
<resource>
<directory>src/main/codegen</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.googlecode.fmpp-maven-plugin</groupId>
<artifactId>fmpp-maven-plugin</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.19</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-fmpp-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<cfgFile>${project.build.directory}/codegen/config.fmpp</cfgFile>
<outputDirectory>target/generated-sources</outputDirectory>
<templateDirectory>${project.build.directory}/codegen/templates</templateDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand All@@ -108,6 +155,29 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>javacc-maven-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>generate-sources</phase>
<id>javacc</id>
<goals>
<goal>javacc</goal>
</goals>
<configuration>
<sourceDirectory>${project.build.directory}/generated-sources/</sourceDirectory>
<includes>
<include>**/Parser.jj</include>
</includes>
<lookAhead>2</lookAhead>
<isStatic>false</isStatic>
<outputDirectory>${project.build.directory}/generated-sources/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- Compile the antlr sources -->
<plugin>
<groupId>org.antlr</groupId>
Expand DownExpand Up@@ -208,6 +278,27 @@
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<!-- Extract parser grammar template from optiq-core.jar and put
it under ${project.build.directory} where all freemarker templates are. -->
<id>unpack-parser-template</id>
<phase>initialize</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/</outputDirectory>
<includes>**/Parser.jj</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<!-- generates the file that will be used by the sandbox script in the dev env -->
<id>create-phoenix-generated-classpath</id>
Expand Down
144 changes: 96 additions & 48 deletions phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
/*
* 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.
*/
package org.apache.phoenix.calcite;

import com.google.common.collect.Lists;
Expand All@@ -10,6 +27,7 @@
import org.apache.phoenix.schema.TableAlreadyExistsException;
import org.apache.phoenix.util.PropertiesUtil;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
Expand DownExpand Up@@ -120,6 +138,18 @@ public Sql explainIs(String expected) {
return this;
}


public boolean execute() {
try {
final Statement statement = start.getConnection().createStatement();
final boolean execute = statement.execute(sql);
statement.close();
return execute;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

public List<Object[]> getResult(String sql) {
try {
final Statement statement = start.getConnection().createStatement();
Expand DownExpand Up@@ -423,25 +453,29 @@ protected void createIndices(String... indexDDL) throws Exception {
{"invalid001", "INVALID-1", null, null}})
.close();

start().sql("select t1.entity_id, t2.a_string, t1.organization_id from aTable t1 join aTable t2 on t1.organization_id = t2.organization_id and t1.entity_id = t2.entity_id")
start().sql("select t1.entity_id, t2.a_string, t1.organization_id from aTable t1 join aTable t2 on t1.organization_id = t2.organization_id and t1.entity_id = t2.entity_id")
.explainIs("PhoenixToEnumerableConverter\n" +
" PhoenixClientProject(ENTITY_ID=[$1], A_STRING=[$4], ORGANIZATION_ID=[$0])\n" +
" PhoenixClientJoin(condition=[AND(=($0, $2), =($1, $3))], joinType=[inner])\n" +
" PhoenixToClientConverter\n" +
" PhoenixServerProject(ORGANIZATION_ID=[$0], ENTITY_ID=[$1])\n" +
" PhoenixTableScan(table=[[phoenix, ATABLE]])\n" +
" PhoenixToClientConverter\n" +
" PhoenixServerProject(ORGANIZATION_ID=[$0], ENTITY_ID=[$1], A_STRING=[$2])\n" +
" PhoenixTableScan(table=[[phoenix, ATABLE]])\n")
" PhoenixClientProject(ENTITY_ID=[$1], A_STRING=[$4], ORGANIZATION_ID=[$0])\n"
+
" PhoenixClientJoin(condition=[AND(=($0, $2), =($1, $3))], joinType=[inner])\n"
+
" PhoenixToClientConverter\n" +
" PhoenixServerProject(ORGANIZATION_ID=[$0], ENTITY_ID=[$1])\n"
+
" PhoenixTableScan(table=[[phoenix, ATABLE]])\n" +
" PhoenixToClientConverter\n" +
" PhoenixServerProject(ORGANIZATION_ID=[$0], ENTITY_ID=[$1], A_STRING=[$2])\n"
+
" PhoenixTableScan(table=[[phoenix, ATABLE]])\n")
.resultIs(new Object[][] {
{"00A123122312312", "a", "00D300000000XHP"},
{"00A223122312312", "a", "00D300000000XHP"},
{"00A323122312312", "a", "00D300000000XHP"},
{"00A423122312312", "a", "00D300000000XHP"},
{"00B523122312312", "b", "00D300000000XHP"},
{"00B623122312312", "b", "00D300000000XHP"},
{"00B723122312312", "b", "00D300000000XHP"},
{"00B823122312312", "b", "00D300000000XHP"},
{"00A123122312312", "a", "00D300000000XHP"},
{"00A223122312312", "a", "00D300000000XHP"},
{"00A323122312312", "a", "00D300000000XHP"},
{"00A423122312312", "a", "00D300000000XHP"},
{"00B523122312312", "b", "00D300000000XHP"},
{"00B623122312312", "b", "00D300000000XHP"},
{"00B723122312312", "b", "00D300000000XHP"},
{"00B823122312312", "b", "00D300000000XHP"},
{"00C923122312312", "c", "00D300000000XHP"}})
.close();
}
Expand DownExpand Up@@ -494,26 +528,30 @@ protected void createIndices(String... indexDDL) throws Exception {
{"00A423122312312", "a", "00D300000000XHP"}})
.close();

start().sql("select t1.entity_id, t2.a_string, t3.organization_id from aTable t1 join aTable t2 on t1.entity_id = t2.entity_id and t1.organization_id = t2.organization_id join atable t3 on t1.entity_id = t3.entity_id and t1.organization_id = t3.organization_id")
start().sql("select t1.entity_id, t2.a_string, t3.organization_id from aTable t1 join aTable t2 on t1.entity_id = t2.entity_id and t1.organization_id = t2.organization_id join atable t3 on t1.entity_id = t3.entity_id and t1.organization_id = t3.organization_id")
.explainIs("PhoenixToEnumerableConverter\n" +
" PhoenixClientProject(ENTITY_ID=[$19], A_STRING=[$2], ORGANIZATION_ID=[$36])\n" +
" PhoenixToClientConverter\n" +
" PhoenixServerJoin(condition=[AND(=($19, $1), =($18, $0))], joinType=[inner])\n" +
" PhoenixTableScan(table=[[phoenix, ATABLE]])\n" +
" PhoenixToClientConverter\n" +
" PhoenixServerJoin(condition=[AND(=($1, $19), =($0, $18))], joinType=[inner])\n" +
" PhoenixTableScan(table=[[phoenix, ATABLE]])\n" +
" PhoenixToClientConverter\n" +
" PhoenixTableScan(table=[[phoenix, ATABLE]])\n")
" PhoenixClientProject(ENTITY_ID=[$19], A_STRING=[$2], ORGANIZATION_ID=[$36])\n"
+
" PhoenixToClientConverter\n" +
" PhoenixServerJoin(condition=[AND(=($19, $1), =($18, $0))], joinType=[inner])\n"
+
" PhoenixTableScan(table=[[phoenix, ATABLE]])\n" +
" PhoenixToClientConverter\n" +
" PhoenixServerJoin(condition=[AND(=($1, $19), =($0, $18))], joinType=[inner])\n"
+
" PhoenixTableScan(table=[[phoenix, ATABLE]])\n"
+
" PhoenixToClientConverter\n" +
" PhoenixTableScan(table=[[phoenix, ATABLE]])\n")
.resultIs(new Object[][] {
{"00A123122312312", "a", "00D300000000XHP"},
{"00A223122312312", "a", "00D300000000XHP"},
{"00A323122312312", "a", "00D300000000XHP"},
{"00A423122312312", "a", "00D300000000XHP"},
{"00B523122312312", "b", "00D300000000XHP"},
{"00B623122312312", "b", "00D300000000XHP"},
{"00B723122312312", "b", "00D300000000XHP"},
{"00B823122312312", "b", "00D300000000XHP"},
{"00A123122312312", "a", "00D300000000XHP"},
{"00A223122312312", "a", "00D300000000XHP"},
{"00A323122312312", "a", "00D300000000XHP"},
{"00A423122312312", "a", "00D300000000XHP"},
{"00B523122312312", "b", "00D300000000XHP"},
{"00B623122312312", "b", "00D300000000XHP"},
{"00B723122312312", "b", "00D300000000XHP"},
{"00B823122312312", "b", "00D300000000XHP"},
{"00C923122312312", "c", "00D300000000XHP"}})
.close();
}
Expand DownExpand Up@@ -816,7 +854,7 @@ protected void createIndices(String... indexDDL) throws Exception {
{"000000000000005", 5000}})
.close();
}

@Test public void testScalarSubquery() {
start().sql("select \"item_id\", name, (select max(quantity) sq \n"
+ "from " + JOIN_ORDER_TABLE_FULL_NAME + " o where o.\"item_id\" = i.\"item_id\")\n"
Expand All@@ -833,12 +871,12 @@ protected void createIndices(String... indexDDL) throws Exception {
" PhoenixServerProject(item_id=[$0])\n" +
" PhoenixTableScan(table=[[phoenix, Join, ItemTable]])\n")
.resultIs(new Object[][] {
new Object[] {"0000000001", "T1", 1000},
new Object[] {"0000000002", "T2", 3000},
new Object[] {"0000000003", "T3", 5000},
new Object[] {"0000000004", "T4", null},
new Object[] {"0000000005", "T5", null},
new Object[] {"0000000006", "T6", 4000},
new Object[] {"0000000001", "T1", 1000},
new Object[] {"0000000002", "T2", 3000},
new Object[] {"0000000003", "T3", 5000},
new Object[] {"0000000004", "T4", null},
new Object[] {"0000000005", "T5", null},
new Object[] {"0000000006", "T6", 4000},
new Object[] {"invalid001", "INVALID-1", null}})
.close();

Expand All@@ -857,10 +895,10 @@ protected void createIndices(String... indexDDL) throws Exception {
" PhoenixServerAggregate(group=[{0}])\n" +
" PhoenixTableScan(table=[[phoenix, Join, ItemTable]], filter=[<($0, '0000000006')])\n")
.resultIs(new Object[][] {
new Object[] {"0000000001", "T1", 1000},
new Object[] {"0000000002", "T2", 3000},
new Object[] {"0000000003", "T3", 5000},
new Object[] {"0000000004", "T4", null},
new Object[] {"0000000001", "T1", 1000},
new Object[] {"0000000002", "T2", 3000},
new Object[] {"0000000003", "T3", 5000},
new Object[] {"0000000004", "T4", null},
new Object[] {"0000000005", "T5", null}})
.close();;
}
Expand DownExpand Up@@ -961,10 +999,20 @@ protected void createIndices(String... indexDDL) throws Exception {
.resultIs(new Object[][] {
{"00C923122312312", "c"},
{"00A423122312312", "a"},
{"00A323122312312", "a"}})
{"00A323122312312", "a"}})
.close();
}


/** Tests a simple command that is defined in Phoenix's extended SQL parser. */
@Ignore
@Test public void testCommit() {
start().sql("commit").execute();
}

@Test public void testCreateView() {
start().sql("create view v as select * from (values (1, 'a'), (2, 'b')) as t(x, y)").execute();
}

@Test public void testConnectJoinHsqldb() {
final Start start = new Start(new Properties(), false) {
@Override
Expand Down
22 changes: 22 additions & 0 deletions phoenix-core/src/main/codegen/config.fmpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
# 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.

data: {
parser: tdd(../data/Parser.tdd)
}
freemarkerLinks: {
includes: includes/
}
Loading