Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade calcite to 1.37.0 #16504

Merged
merged 68 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
da53d2e
Upgrade Calcite to 1.36.0
kgyrtkirk Apr 10, 2024
f9aee29
add test
kgyrtkirk Apr 10, 2024
92f340e
Revert "add test"
kgyrtkirk Apr 10, 2024
6303057
add fixme-s
kgyrtkirk Apr 10, 2024
adb37a0
up
kgyrtkirk Apr 12, 2024
f1c8173
Revert "up"
kgyrtkirk Apr 12, 2024
66cef7c
add some expr
kgyrtkirk Apr 15, 2024
b723365
add case_searched
kgyrtkirk Apr 16, 2024
6f99b8c
NULLX
kgyrtkirk Apr 16, 2024
c54a125
fixes
kgyrtkirk Apr 16, 2024
249fde1
update onemore
kgyrtkirk Apr 17, 2024
7c2dea8
Merge remote-tracking branch 'apache/master' into upgrade-calcite-1.36.0
kgyrtkirk May 27, 2024
ed5bb92
accept column swap
kgyrtkirk May 28, 2024
da157a7
remove nullx
kgyrtkirk May 28, 2024
886aa79
disable
kgyrtkirk May 28, 2024
5997aa9
Revert "disable"
kgyrtkirk May 28, 2024
e10d1d6
flatten stage
kgyrtkirk May 28, 2024
3431916
Revert "Revert "disable""
kgyrtkirk May 28, 2024
538a5a1
flatten from.ftl
kgyrtkirk May 28, 2024
d5dc46f
remove ftl uses
kgyrtkirk May 28, 2024
46050e6
remove
kgyrtkirk May 28, 2024
8c76c38
cleanup pom.xml
kgyrtkirk May 28, 2024
1e82460
update base calcite parser sources
kgyrtkirk May 28, 2024
03a439d
update base calcite parser sources
kgyrtkirk May 28, 2024
388b209
undo unrelated
kgyrtkirk May 28, 2024
a0fd66e
update script
kgyrtkirk May 28, 2024
1770fdf
rename/etc
kgyrtkirk May 28, 2024
b8568f4
Merge branch 'calcite-remove-build-tricks' into upgrade-calcite-1.36.0
kgyrtkirk May 28, 2024
c3af179
add old/new to script
kgyrtkirk May 28, 2024
6e17ffe
upd
kgyrtkirk May 28, 2024
8e2f1b8
1.37
kgyrtkirk May 28, 2024
2b698d7
1.35
kgyrtkirk May 28, 2024
57d060a
current reverse
kgyrtkirk May 28, 2024
073d4dd
Revert "current reverse"
kgyrtkirk May 28, 2024
42af8f2
base-changes
kgyrtkirk May 28, 2024
bb2b7d8
Merge branch 'curr-changes' into new-state
kgyrtkirk May 28, 2024
cf5560a
cleaner run
kgyrtkirk May 28, 2024
2bdc656
137
kgyrtkirk May 28, 2024
653f268
fix 1.37 api upgrade
kgyrtkirk May 28, 2024
32deca2
remove check
kgyrtkirk May 28, 2024
154318f
update 1
kgyrtkirk May 28, 2024
ba10110
order change
kgyrtkirk May 28, 2024
6876a2d
split test; accept working query
kgyrtkirk May 28, 2024
1b0e2d3
some
kgyrtkirk May 28, 2024
06bf8e7
f
kgyrtkirk May 28, 2024
e435700
f
kgyrtkirk May 28, 2024
81ac585
prep
kgyrtkirk May 28, 2024
afc08d2
fix
kgyrtkirk May 28, 2024
ac60908
cleanup
kgyrtkirk May 28, 2024
c380c06
fix some
kgyrtkirk May 28, 2024
13a0459
still slight worse
kgyrtkirk May 28, 2024
76076ba
disable testcase for decoupled mode
kgyrtkirk May 28, 2024
2550e04
update script
kgyrtkirk May 28, 2024
c3a5e48
Merge remote-tracking branch 'kgyrtkirk/calcite-remove-build-tricks' …
kgyrtkirk May 28, 2024
3a81b35
disable new testcase
kgyrtkirk May 28, 2024
fef4b86
avatica 1.25
kgyrtkirk May 28, 2024
4d8fb57
license
kgyrtkirk May 29, 2024
0f57547
avatica update
kgyrtkirk May 29, 2024
4426cf5
ignore iq.out
kgyrtkirk May 29, 2024
250738b
Merge remote-tracking branch 'apache/master' into upgrade-calcite-1.36.0
kgyrtkirk Jun 5, 2024
14c96e8
add comment/elvis
kgyrtkirk Jun 5, 2024
98390d1
remove extra test
kgyrtkirk Jun 5, 2024
40e6595
Merge remote-tracking branch 'apache/master' into upgrade-calcite-1.36.0
kgyrtkirk Jun 11, 2024
13a7ea7
fix typo in resultset
kgyrtkirk Jun 11, 2024
6a15e14
cleanup
kgyrtkirk Jun 11, 2024
5d141b9
fix typo :facepalm:
kgyrtkirk Jun 12, 2024
3d1540a
Merge remote-tracking branch 'apache/master' into upgrade-calcite-1.36.0
kgyrtkirk Jun 12, 2024
d5942d0
remove cannotVectorize from a CalciteSubqueryTest#testSingleValueStri…
kgyrtkirk Jun 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 72 additions & 0 deletions dev/updgrade-calcite-parser
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
kgyrtkirk marked this conversation as resolved.
Show resolved Hide resolved

# 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.
#--------------------------------------------------------------------

# Adopts base Calcite parser changes
#
# Establishes a git friendly merge situation:
#
# Creates a commit which matches the original state of the calcite parser;
# To this point creates to alternates:
# * one with local customizations
# * another with all the upstream updates
# merges the two branches to obtain the upgrade state
#

[ $# -ne 2 ] && echo -e "updates base parser sources.\n usage: $0 <old_calcite_version> <new_calcite_version>" && exit 1

CALCITE_OLD=$1
CALCITE_NEW=$2

set -e
set -x

BRANCH=`git name-rev --name-only HEAD`

REPO=.git/calcite-upgrade
rm -rf "$REPO"
git clone $PWD --reference $PWD --branch $BRANCH $REPO

cd "$REPO"
git checkout -b curr-changes

mvn -q generate-sources -pl sql -Dcalcite.version=$CALCITE_OLD -Pskip-static-checks
cp -r sql/target/calcite-base-parser/codegen/./ sql/src/main/codegen/./
git commit -m 'current reverse' -a
git revert --no-edit HEAD
# HEAD is now at the same as before; but parent are the base calcite changes

git branch base-changes curr-changes^
git checkout base-changes
git show|patch -p0 -R # undo temproarily to ensure maven runs

mvn -q generate-sources -pl sql -Dcalcite.version=$CALCITE_NEW -Pskip-static-checks
cp -r sql/target/calcite-base-parser/codegen/./ sql/src/main/codegen/./

git commit --allow-empty -m base-changes -a
git checkout -b new-state
git merge --no-edit curr-changes

echo ok
cd -

git remote remove calcite-upgrade &>/dev/null || echo -n
git remote add -f calcite-upgrade "$REPO"


echo "merge branch calcite-upgrade/curr-changes if satisfied with those changes"

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.common.base.Preconditions;
import org.apache.calcite.runtime.Hook;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.util.Pair;
import org.apache.druid.common.guava.FutureUtils;
import org.apache.druid.error.DruidException;
import org.apache.druid.error.InvalidInput;
Expand Down Expand Up @@ -78,6 +77,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;

Expand All @@ -91,15 +91,15 @@ public class MSQTaskQueryMaker implements QueryMaker
private final OverlordClient overlordClient;
private final PlannerContext plannerContext;
private final ObjectMapper jsonMapper;
private final List<Pair<Integer, String>> fieldMapping;
private final List<Entry<Integer, String>> fieldMapping;


MSQTaskQueryMaker(
@Nullable final IngestDestination targetDataSource,
final OverlordClient overlordClient,
final PlannerContext plannerContext,
final ObjectMapper jsonMapper,
final List<Pair<Integer, String>> fieldMapping
final List<Entry<Integer, String>> fieldMapping
)
{
this.targetDataSource = targetDataSource;
Expand Down Expand Up @@ -193,7 +193,7 @@ public QueryResponse<Object[]> runQuery(final DruidQuery druidQuery)
final List<ColumnType> columnTypeList = new ArrayList<>();
final List<ColumnMapping> columnMappings = QueryUtils.buildColumnMappings(fieldMapping, druidQuery);

for (final Pair<Integer, String> entry : fieldMapping) {
for (final Entry<Integer, String> entry : fieldMapping) {
final String queryColumn = druidQuery.getOutputRowSignature().getColumnName(entry.getKey());

final SqlTypeName sqlTypeName;
Expand Down Expand Up @@ -238,7 +238,7 @@ public QueryResponse<Object[]> runQuery(final DruidQuery druidQuery)

MSQTaskQueryMakerUtils.validateSegmentSortOrder(
segmentSortOrder,
fieldMapping.stream().map(f -> f.right).collect(Collectors.toList())
fieldMapping.stream().map(f -> f.getValue()).collect(Collectors.toList())
);

final DataSourceMSQDestination dataSourceMSQDestination = new DataSourceMSQDestination(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.apache.calcite.schema.Table;
import org.apache.calcite.sql.dialect.CalciteSqlDialect;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.util.Pair;
import org.apache.druid.error.DruidException;
import org.apache.druid.error.InvalidInput;
import org.apache.druid.error.InvalidSqlInput;
Expand Down Expand Up @@ -65,6 +64,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class MSQTaskSqlEngine implements SqlEngine
Expand Down Expand Up @@ -222,7 +222,7 @@ private static void validateSelect(final PlannerContext plannerContext)
*/
private static void validateInsert(
final RelNode rootRel,
final List<Pair<Integer, String>> fieldMappings,
final List<Entry<Integer, String>> fieldMappings,
@Nullable Table targetTable,
final PlannerContext plannerContext
)
Expand All @@ -241,13 +241,13 @@ private static void validateInsert(
* SQL allows multiple output columns with the same name. However, we don't allow this for INSERT or REPLACE
* queries, because we use these output names to generate columns in segments. They must be unique.
*/
private static void validateNoDuplicateAliases(final List<Pair<Integer, String>> fieldMappings)
private static void validateNoDuplicateAliases(final List<Entry<Integer, String>> fieldMappings)
{
final Set<String> aliasesSeen = new HashSet<>();

for (final Pair<Integer, String> field : fieldMappings) {
if (!aliasesSeen.add(field.right)) {
throw InvalidSqlInput.exception("Duplicate field in SELECT: [%s]", field.right);
for (final Entry<Integer, String> field : fieldMappings) {
if (!aliasesSeen.add(field.getValue())) {
throw InvalidSqlInput.exception("Duplicate field in SELECT: [%s]", field.getValue());
}
}
}
Expand Down Expand Up @@ -353,7 +353,7 @@ private static void validateLimitAndOffset(final RelNode rootRel, final boolean
*/
private static void validateTypeChanges(
final RelNode rootRel,
final List<Pair<Integer, String>> fieldMappings,
final List<Entry<Integer, String>> fieldMappings,
@Nullable final Table targetTable,
final PlannerContext plannerContext
)
Expand All @@ -366,9 +366,9 @@ private static void validateTypeChanges(
MultiStageQueryContext.getColumnsExcludedFromTypeVerification(plannerContext.queryContext());
final ArrayIngestMode arrayIngestMode = MultiStageQueryContext.getArrayIngestMode(plannerContext.queryContext());

for (Pair<Integer, String> fieldMapping : fieldMappings) {
final int columnIndex = fieldMapping.left;
final String columnName = fieldMapping.right;
for (Entry<Integer, String> fieldMapping : fieldMappings) {
final int columnIndex = fieldMapping.getKey();
final String columnName = fieldMapping.getValue();
final RelDataTypeField oldSqlTypeField =
targetTable.getRowType(DruidTypeSystem.TYPE_FACTORY).getField(columnName, true, false);

Expand Down Expand Up @@ -427,11 +427,11 @@ private static void validateTypeChanges(
*
* Returns -1 if the list does not contain a time column.
*/
private static int getTimeColumnIndex(final List<Pair<Integer, String>> fieldMappings)
private static int getTimeColumnIndex(final List<Entry<Integer, String>> fieldMappings)
{
for (final Pair<Integer, String> field : fieldMappings) {
if (field.right.equals(ColumnHolder.TIME_COLUMN_NAME)) {
return field.left;
for (final Entry<Integer, String> field : fieldMappings) {
if (field.getValue().equals(ColumnHolder.TIME_COLUMN_NAME)) {
return field.getKey();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ public void testExactCountDistinctWithFilter()

}

@Disabled
@Override
@Test
public void testExactCountDistinctWithFilter2()
{

}

@Disabled
@Override
@Test
Expand Down
4 changes: 2 additions & 2 deletions licenses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ name: Apache Calcite
license_category: binary
module: java-core
license_name: Apache License version 2.0
version: 1.35.0
version: 1.37.0
libraries:
- org.apache.calcite: calcite-core
- org.apache.calcite: calcite-linq4j
Expand All @@ -1634,7 +1634,7 @@ name: Apache Calcite Avatica
license_category: binary
module: java-core
license_name: Apache License version 2.0
version: 1.23.0
version: 1.25.0
libraries:
- org.apache.calcite.avatica: avatica-core
- org.apache.calcite.avatica: avatica-metrics
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@
<apache.ranger.version>2.4.0</apache.ranger.version>
<gson.version>2.10.1</gson.version>
<scala.library.version>2.13.14</scala.library.version>
<avatica.version>1.23.0</avatica.version>
<avatica.version>1.25.0</avatica.version>
<avro.version>1.11.3</avro.version>
<!-- When updating Calcite, also propagate updates to these files which we've copied and modified:
default_config.fmpp
sql/src/main/codegen/includes/*
<!--
The base calcite parser was copied into the project; when updating Calcite run dev/updgrade-calcite-parser to adopt upstream changes
-->
<calcite.version>1.35.0</calcite.version>
<calcite.version>1.37.0</calcite.version>
<confluent.version>6.2.12</confluent.version>
<datasketches.version>4.2.0</datasketches.version>
<datasketches.memory.version>2.2.0</datasketches.memory.version>
Expand Down Expand Up @@ -2189,6 +2188,7 @@
<exclude>**/.classpath</exclude> <!-- Eclipse -->
<exclude>**/.project</exclude> <!-- Eclipse -->
<exclude>**/*.iq</exclude> <!-- quidem testfiles -->
<exclude>**/*.iq.out</exclude> <!-- quidem testfiles -->
</excludes>
</configuration>
</plugin>
Expand Down
3 changes: 3 additions & 0 deletions processing/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
<Logger level="info" name="org.apache.druid" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
<Logger level="debug" name="org.apache.calcite.plan.AbstractRelOptPlanner.rule_execution_summary" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
</Loggers>
</Configuration>
80 changes: 7 additions & 73 deletions sql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@
</executions>
</plugin>

<!-- Following plugins and their configurations are used to generate the custom Calcite's SQL parser for Druid -->
<!-- Extracts the Parser.jj from Calcite to ${project.build.directory}, where all the Freemarker templates are -->
<!-- Extracts the base parser from the calcite-core artifcat. -->
<!-- This is provided to have the base available - to compare changes to -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand All @@ -353,50 +353,16 @@
<version>${calcite.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/</outputDirectory>
<includes>**/Parser.jj</includes>
</artifactItem>
<artifactItem>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<version>${calcite.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/</outputDirectory>
<includes>**/default_config.fmpp</includes>
<outputDirectory>${project.build.directory}/calcite-base-parser</outputDirectory>
<includes>codegen/**</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

<!-- Copy the templates present in the codegen directory of druid-sql containing custom SQL rules to
${project.build.directory}/codegen -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-fmpp-resources</id>
<phase>generate-sources</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>

<!-- "Plugs in" the Calcite's Parser.jj with the variables present in config.fmpp. These contain the custom rules
as well as the class to which the custom implementation will get generated -->
<!-- Applies the fmpp templates to produce the final Parser.jj -->
<plugin>
<groupId>com.googlecode.fmpp-maven-plugin</groupId>
<artifactId>fmpp-maven-plugin</artifactId>
Expand All @@ -408,9 +374,9 @@
<goal>generate</goal>
</goals>
<configuration>
<cfgFile>${project.build.directory}/codegen/config.fmpp</cfgFile>
<cfgFile>src/main/codegen/config.fmpp</cfgFile>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
<templateDirectory>${project.build.directory}/codegen/templates</templateDirectory>
<templateDirectory>src/main/codegen/templates</templateDirectory>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -440,38 +406,6 @@
</executions>
</plugin>

<!-- This plugin is used to replace the production rule for FROM clause in the calcite grammar.
It is done by a search and replace since calcite doesn't allow to override production rules generally
in its grammar (override is possible only if there's a hook for it in the grammar). And the FROM clause
doesn't contain any hook for extension. For the custom changes done in
extension, please check from.ftl file in sql module.
-->
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${project.build.directory}/generated-sources/org/apache/druid/sql/calcite/parser</basedir>
<includes>
<include>**/DruidSqlParserImpl.java</include>
</includes>
<replacements>
<replacement>
<token>fromClause = FromClause</token>
<value>fromClause = DruidFromClause</value>
</replacement>
</replacements>
</configuration>
</plugin>

<!-- Adds the path of the generated parser to the build path -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down