-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose Druid functions in
INFORMATION_SCHEMA.ROUTINES
table. (#14378)
* Add INFORMATION_SCHEMA.ROUTINES to expose Druid operators and functions. * checkstyle * remove IS_DETERMISITIC. * test * cleanup test * remove logs and simplify * fixup unit test * Add docs for INFORMATION_SCHEMA.ROUTINES table. * Update test and add another SQL query. * add stuff to .spelling and checkstyle fix. * Add more tests for custom operators. * checkstyle and comment. * Some naming cleanup. * Add FUNCTION_ID * The different Calcite function syntax enums get translated to FUNCTION * Update docs. * Cleanup markdown table. * fixup test. * fixup intellij inspection * Review comment: nullable column; add a function to determine function syntax. * More tests; add non-function syntax operators. * More unit tests. Also add a separate test for DruidOperatorTable. * actually just validate non-zero count. * switch up the order * checkstyle fixes.
- Loading branch information
1 parent
61120dc
commit b8495d4
Showing
9 changed files
with
523 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
sql/src/test/java/org/apache/druid/sql/calcite/planner/DruidOperatorTableTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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.druid.sql.calcite.planner; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import org.apache.calcite.sql.SqlFunctionCategory; | ||
import org.apache.calcite.sql.SqlOperator; | ||
import org.apache.calcite.sql.SqlSyntax; | ||
import org.apache.calcite.sql.fun.SqlStdOperatorTable; | ||
import org.apache.calcite.sql.type.SqlTypeFamily; | ||
import org.apache.druid.segment.column.ColumnType; | ||
import org.apache.druid.sql.calcite.expression.DirectOperatorConversion; | ||
import org.apache.druid.sql.calcite.expression.OperatorConversions; | ||
import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; | ||
import org.apache.druid.sql.calcite.table.RowSignatures; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class DruidOperatorTableTest | ||
{ | ||
@Test | ||
public void testBuiltInOperatorTable() | ||
{ | ||
DruidOperatorTable operatorTable = new DruidOperatorTable(ImmutableSet.of(), ImmutableSet.of()); | ||
List<SqlOperator> operatorList = operatorTable.getOperatorList(); | ||
Assert.assertNotNull(operatorList); | ||
Assert.assertTrue("Built-in operators should be loaded by default", operatorList.size() > 0); | ||
} | ||
|
||
@Test | ||
public void testIsFunctionSyntax() | ||
{ | ||
Assert.assertTrue(DruidOperatorTable.isFunctionSyntax(SqlSyntax.FUNCTION)); | ||
Assert.assertTrue(DruidOperatorTable.isFunctionSyntax(SqlSyntax.FUNCTION_STAR)); | ||
Assert.assertTrue(DruidOperatorTable.isFunctionSyntax(SqlSyntax.FUNCTION_ID)); | ||
Assert.assertTrue(DruidOperatorTable.isFunctionSyntax(SqlSyntax.SPECIAL)); | ||
Assert.assertTrue(DruidOperatorTable.isFunctionSyntax(SqlSyntax.INTERNAL)); | ||
|
||
Assert.assertFalse(DruidOperatorTable.isFunctionSyntax(SqlSyntax.BINARY)); | ||
Assert.assertFalse(DruidOperatorTable.isFunctionSyntax(SqlSyntax.PREFIX)); | ||
Assert.assertFalse(DruidOperatorTable.isFunctionSyntax(SqlSyntax.POSTFIX)); | ||
} | ||
|
||
@Test | ||
public void testCustomOperatorTable() | ||
{ | ||
final SqlOperator operator1 = OperatorConversions | ||
.operatorBuilder("FOO") | ||
.operandTypes(SqlTypeFamily.ANY) | ||
.requiredOperands(0) | ||
.returnTypeInference( | ||
opBinding -> RowSignatures.makeComplexType( | ||
opBinding.getTypeFactory(), | ||
ColumnType.ofComplex("fooComplex"), | ||
true | ||
) | ||
) | ||
.functionCategory(SqlFunctionCategory.USER_DEFINED_FUNCTION) | ||
.build(); | ||
|
||
final SqlOperator operator2 = SqlStdOperatorTable.PLUS; | ||
final Set<SqlOperatorConversion> extractionOperators = new HashSet<>(); | ||
|
||
extractionOperators.add(new DirectOperatorConversion(operator1, "foo_fn")); | ||
extractionOperators.add(new DirectOperatorConversion(operator2, "plus_is_not_a_fn")); | ||
|
||
DruidOperatorTable operatorTable = new DruidOperatorTable(ImmutableSet.of(), extractionOperators); | ||
List<SqlOperator> operatorList = operatorTable.getOperatorList(); | ||
Assert.assertNotNull(operatorList); | ||
Assert.assertTrue("We should have at least two operators -- the ones we loaded above plus the built-in" | ||
+ " operators that gets loaded by default", operatorList.size() > 2); | ||
|
||
Assert.assertTrue(operatorList.contains(operator1)); | ||
Assert.assertTrue(operatorList.contains(operator2)); | ||
|
||
Assert.assertTrue(DruidOperatorTable.isFunctionSyntax(operator1.getSyntax())); | ||
Assert.assertFalse(DruidOperatorTable.isFunctionSyntax(operator2.getSyntax())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.