DRILL-3894: Upgrade functions MaxDir, MinDir... Optional filename parameter - added implementations of functions MAXDIR, IMAXDIR, MINDIR, IMINDIR with one (schema) without filename argument; - added UTest for results comparison of using Query Directory Functions with one and two arguments. This closes #467 Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/a6a85ab6 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/a6a85ab6 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/a6a85ab6 Branch: refs/heads/master Commit: a6a85ab66360cac81ab4777cec20292470ac483d Parents: 38e1016 Author: Vitalii Diravka Authored: Tue Apr 5 15:07:29 2016 +0000 Committer: Parth Chandra Committed: Tue May 3 10:50:09 2016 -0700 ---------------------------------------------------------------------- .../codegen/templates/DirectoryExplorers.java | 23 ++++++++++++++++++ .../exec/planner/TestDirectoryExplorerUDFs.java | 25 ++++++++++++++++++++ 2 files changed, 48 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/a6a85ab6/exec/java-exec/src/main/codegen/templates/DirectoryExplorers.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/DirectoryExplorers.java b/exec/java-exec/src/main/codegen/templates/DirectoryExplorers.java index 655ff81..a47a541 100644 --- a/exec/java-exec/src/main/codegen/templates/DirectoryExplorers.java +++ b/exec/java-exec/src/main/codegen/templates/DirectoryExplorers.java @@ -43,6 +43,11 @@ public class DirectoryExplorers { { "name" : "\"imaxdir\"", "functionClassName" : "IMaxDir", "comparison" : "compareToIgnoreCase(curr) < 0", "goal" : "maximum", "comparisonType" : "case-insensitive"}, { "name" : "\"mindir\"", "functionClassName" : "MinDir", "comparison" : "compareTo(curr) > 0", "goal" : "minimum", "comparisonType" : "case-sensitive"}, { "name" : "\"imindir\"", "functionClassName" : "IMinDir", "comparison" : "compareToIgnoreCase(curr) > 0", "goal" : "minimum", "comparisonType" : "case-insensitive"} + + { "name" : "\"maxdir\"", "functionClassName" : "MaxDirTwoArg", "comparison" : "compareTo(curr) < 0", "goal" : "maximum", "comparisonType" : "case-sensitive"}, + { "name" : "\"imaxdir\"", "functionClassName" : "IMaxDirTwoArg", "comparison" : "compareToIgnoreCase(curr) < 0", "goal" : "maximum", "comparisonType" : "case-insensitive"}, + { "name" : "\"mindir\"", "functionClassName" : "MinDirTwoArg", "comparison" : "compareTo(curr) > 0", "goal" : "minimum", "comparisonType" : "case-sensitive"}, + { "name" : "\"imindir\"", "functionClassName" : "IMinDirTwoArg", "comparison" : "compareToIgnoreCase(curr) > 0", "goal" : "minimum", "comparisonType" : "case-insensitive"} ] as dirAggrProps> @@ -50,7 +55,9 @@ public class DirectoryExplorers { public static class ${dirAggrProps.functionClassName} implements DrillSimpleFunc { @Param VarCharHolder schema; + <#if dirAggrProps.functionClassName?ends_with("TwoArg")> @Param VarCharHolder table; + @Output VarCharHolder out; @Inject DrillBuf buffer; @Inject org.apache.drill.exec.store.PartitionExplorer partitionExplorer; @@ -63,23 +70,39 @@ public class DirectoryExplorers { try { subPartitions = partitionExplorer.getSubPartitions( org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getStringFromVarCharHolder(schema), + <#if dirAggrProps.functionClassName?ends_with("TwoArg")> org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getStringFromVarCharHolder(table), + <#else> + ".", + new java.util.ArrayList(), new java.util.ArrayList()); } catch (org.apache.drill.exec.store.PartitionNotFoundException e) { throw new RuntimeException( + <#if dirAggrProps.functionClassName?ends_with("TwoArg")> String.format("Error in %s function: Table %s does not exist in schema %s ", + <#else> + String.format("Error in %s function: Schema/table %s does not exist ", + ${dirAggrProps.name}, + <#if dirAggrProps.functionClassName?ends_with("TwoArg")> org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getStringFromVarCharHolder(table), + org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getStringFromVarCharHolder(schema)) ); } java.util.Iterator partitionIterator = subPartitions.iterator(); if (!partitionIterator.hasNext()) { throw new RuntimeException( + <#if dirAggrProps.functionClassName?ends_with("TwoArg")> String.format("Error in %s function: Table %s in schema %s does not contain sub-partitions.", + <#else> + String.format("Error in %s function: Schema/table %s does not contain sub-partitions.", + ${dirAggrProps.name}, + <#if dirAggrProps.functionClassName?ends_with("TwoArg")> org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getStringFromVarCharHolder(table), + org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getStringFromVarCharHolder(schema) ) ); http://git-wip-us.apache.org/repos/asf/drill/blob/a6a85ab6/exec/java-exec/src/test/java/org/apache/drill/exec/planner/TestDirectoryExplorerUDFs.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/planner/TestDirectoryExplorerUDFs.java b/exec/java-exec/src/test/java/org/apache/drill/exec/planner/TestDirectoryExplorerUDFs.java index c3427f6..a5916a5 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/planner/TestDirectoryExplorerUDFs.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/planner/TestDirectoryExplorerUDFs.java @@ -24,7 +24,9 @@ import com.google.common.collect.ImmutableMap; import org.apache.drill.PlanTestBase; import org.apache.drill.common.exceptions.UserRemoteException; import org.apache.drill.exec.fn.interp.TestConstantFolding; +import org.apache.drill.exec.store.StoragePluginRegistry; import org.apache.drill.exec.util.JsonStringArrayList; +import org.apache.drill.exec.util.TestUtilities; import org.apache.drill.exec.util.Text; import org.junit.Before; import org.junit.BeforeClass; @@ -163,4 +165,27 @@ public class TestDirectoryExplorerUDFs extends PlanTestBase { test("set `planner.enable_constant_folding` = true;"); } } + + @Test + public void testOneArgQueryDirFunctions() throws Exception { + //Initially update the location of dfs_test.tmp workspace with "path" temp directory just for use in this UTest + final StoragePluginRegistry pluginRegistry = getDrillbitContext().getStorage(); + try { + TestUtilities.updateDfsTestTmpSchemaLocation(pluginRegistry, path); + + //Results comparison of using Query Directory Functions (MAXDIR, IMAXDIR, MINDIR, IMINDIR) with one and two arguments + String queryWithTwoArgFunc = "select * from dfs.`" + path + "/*/*.csv` where dir0 = %s('dfs.root','" + path + "')"; + String queryWithOneArgFunc = "select * from dfs.`" + path + "/*/*.csv` where dir0 = %s('dfs_test.tmp')"; + for (ConstantFoldingTestConfig config : tests) { + testBuilder() + .sqlQuery(String.format(queryWithOneArgFunc, config.funcName)) + .unOrdered() + .sqlBaselineQuery(String.format(queryWithTwoArgFunc, config.funcName)) + .go(); + } + } finally { + TestUtilities.updateDfsTestTmpSchemaLocation(pluginRegistry, getDfsTestTmpSchemaLocation()); + } + } + }