TAJO-906: Runtime code generation for evaluating expression trees.
Closes #113
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/7603a3d4
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/7603a3d4
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/7603a3d4
Branch: refs/heads/master
Commit: 7603a3d4c9ebf1e98a9f2aba53ae1140cdd34497
Parents: 839081a
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Sun Aug 24 02:36:37 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Sun Aug 24 02:36:37 2014 +0900
----------------------------------------------------------------------
CHANGES | 3 +
LICENSE | 31 +
pom.xml | 52 +-
tajo-algebra/pom.xml | 13 +-
tajo-catalog/pom.xml | 12 +-
tajo-catalog/tajo-catalog-client/pom.xml | 13 +-
tajo-catalog/tajo-catalog-common/pom.xml | 13 +-
.../org/apache/tajo/catalog/CatalogUtil.java | 2 +-
.../org/apache/tajo/catalog/FunctionDesc.java | 2 +-
tajo-catalog/tajo-catalog-drivers/pom.xml | 11 +-
.../tajo-catalog-drivers/tajo-hcatalog/pom.xml | 19 +-
tajo-catalog/tajo-catalog-server/pom.xml | 20 +-
tajo-client/pom.xml | 14 +-
tajo-common/pom.xml | 13 +-
.../main/java/org/apache/tajo/SessionVars.java | 2 +-
.../java/org/apache/tajo/conf/TajoConf.java | 2 +-
.../java/org/apache/tajo/datum/CharDatum.java | 5 +-
.../main/java/org/apache/tajo/datum/Datum.java | 4 +
.../org/apache/tajo/datum/DatumFactory.java | 32 +-
.../java/org/apache/tajo/datum/Inet4Datum.java | 5 +
.../java/org/apache/tajo/datum/NullDatum.java | 5 +
.../org/apache/tajo/util/CommonTestingUtil.java | 24 +-
.../main/java/org/apache/tajo/util/Pair.java | 14 +-
.../apache/tajo/util/datetime/DateTimeUtil.java | 35 +
tajo-core/pom.xml | 34 +-
.../tajo/engine/codegen/CaseWhenEmitter.java | 210 ++
.../engine/codegen/CaseWhenSwitchGenerator.java | 92 +
.../tajo/engine/codegen/CodeGenUtils.java | 41 +
.../tajo/engine/codegen/CompilationError.java | 31 +
.../tajo/engine/codegen/EvalCodeEmitter.java | 27 +
.../tajo/engine/codegen/EvalCodeGenContext.java | 223 ++
.../tajo/engine/codegen/EvalCodeGenerator.java | 840 ++++++
.../engine/codegen/ExecutorPreCompiler.java | 213 ++
.../tajo/engine/codegen/TajoClassLoader.java | 30 +
.../engine/codegen/TajoGeneratorAdapter.java | 953 +++++++
.../engine/codegen/VariablesPreBuilder.java | 83 +
.../org/apache/tajo/engine/eval/BinaryEval.java | 1 +
.../org/apache/tajo/engine/eval/EvalNode.java | 2 -
.../apache/tajo/engine/eval/EvalTreeUtil.java | 16 +-
.../org/apache/tajo/engine/eval/EvalType.java | 10 +
.../apache/tajo/engine/eval/FunctionEval.java | 11 +-
.../tajo/engine/eval/LikePredicateEval.java | 4 +
.../engine/eval/PatternMatchPredicateEval.java | 8 +
.../engine/eval/SimilarToPredicateEval.java | 5 +
.../tajo/engine/eval/SimpleEvalNodeVisitor.java | 3 -
.../function/builtin/CoalesceBoolean.java | 4 +-
.../engine/function/builtin/CoalesceDate.java | 3 +-
.../engine/function/builtin/CoalesceDouble.java | 3 +-
.../engine/function/builtin/CoalesceLong.java | 3 +-
.../engine/function/builtin/CoalesceString.java | 3 +-
.../engine/function/builtin/CoalesceTime.java | 3 +-
.../function/builtin/CoalesceTimestamp.java | 3 +-
.../tajo/engine/planner/ExprAnnotator.java | 15 +-
.../engine/planner/PhysicalPlannerImpl.java | 4 +
.../apache/tajo/engine/planner/Projector.java | 33 +-
.../tajo/engine/planner/logical/HavingNode.java | 15 +-
.../tajo/engine/planner/logical/ScanNode.java | 12 +-
.../engine/planner/logical/SelectableNode.java | 48 +
.../engine/planner/logical/SelectionNode.java | 15 +-
.../engine/planner/physical/BNLJoinExec.java | 9 +-
.../planner/physical/BSTIndexScanExec.java | 2 +-
.../physical/BasicPhysicalExecutorVisitor.java | 2 +
.../planner/physical/BinaryPhysicalExec.java | 2 +
.../planner/physical/ExternalSortExec.java | 1 +
.../planner/physical/HashFullOuterJoinExec.java | 8 +-
.../engine/planner/physical/HashJoinExec.java | 7 +-
.../planner/physical/HashLeftOuterJoinExec.java | 7 +-
.../planner/physical/HashLeftSemiJoinExec.java | 4 +
.../physical/MergeFullOuterJoinExec.java | 7 +-
.../engine/planner/physical/MergeJoinExec.java | 7 +-
.../engine/planner/physical/NLJoinExec.java | 2 +-
.../planner/physical/NLLeftOuterJoinExec.java | 2 +-
.../physical/PartitionMergeScanExec.java | 5 +-
.../engine/planner/physical/PhysicalExec.java | 11 +-
.../physical/PhysicalExecutorVisitor.java | 2 +
.../planner/physical/PhysicalPlanUtil.java | 1 +
.../physical/PhysicalPlanningException.java | 31 -
.../engine/planner/physical/ProjectionExec.java | 2 +-
.../physical/RightOuterMergeJoinExec.java | 7 +-
.../engine/planner/physical/SelectionExec.java | 8 +-
.../engine/planner/physical/SeqScanExec.java | 34 +-
.../planner/physical/UnaryPhysicalExec.java | 5 +
.../tajo/engine/query/QueryUnitRequestImpl.java | 2 +-
.../org/apache/tajo/master/GlobalEngine.java | 14 +-
.../tajo/master/LaunchTaskRunnersEvent.java | 45 +
.../apache/tajo/master/TajoContainerProxy.java | 10 +-
.../java/org/apache/tajo/master/TajoMaster.java | 2 +-
.../tajo/master/querymaster/QueryMaster.java | 1 -
.../tajo/master/querymaster/SubQuery.java | 7 +-
.../worker/ExecutionBlockSharedResource.java | 139 +
.../tajo/worker/TajoResourceAllocator.java | 14 +-
.../java/org/apache/tajo/worker/TajoWorker.java | 31 +-
.../tajo/worker/TajoWorkerManagerService.java | 20 +-
.../main/java/org/apache/tajo/worker/Task.java | 61 +-
.../apache/tajo/worker/TaskAttemptContext.java | 30 +-
.../src/main/proto/TajoWorkerProtocol.proto | 3 +
.../apache/tajo/LocalTajoTestingUtility.java | 6 +-
.../org/apache/tajo/TajoTestingCluster.java | 8 +-
.../engine/codegen/TestEvalCodeGenerator.java | 311 ++
.../engine/codegen/TestGeneratorAdapter.java | 41 +
.../apache/tajo/engine/eval/ExprTestBase.java | 83 +-
.../apache/tajo/engine/eval/TestPredicates.java | 17 +
.../tajo/engine/eval/TestSQLExpression.java | 24 +-
.../function/TestConditionalExpressions.java | 123 +-
.../function/TestPatternMatchingPredicates.java | 2 +-
.../planner/physical/TestPhysicalPlanner.java | 6 +-
.../org/apache/tajo/worker/TestFetcher.java | 13 +-
.../TestTajoCli/testHelpSessionVars.result | 1 +
tajo-dist/pom.xml | 22 +
tajo-dist/src/main/bin/tajo | 4 +-
tajo-docs/pom.xml | 18 +
tajo-jdbc/pom.xml | 13 +-
.../org/apache/tajo/jdbc/MetaDataTuple.java | 6 +
tajo-maven-plugins/pom.xml | 12 +
tajo-project/pom.xml | 23 +-
tajo-rpc/pom.xml | 12 +
tajo-storage/pom.xml | 18 +-
.../org/apache/tajo/storage/FrameTuple.java | 6 +
.../java/org/apache/tajo/storage/LazyTuple.java | 9 +-
.../java/org/apache/tajo/storage/Tuple.java | 3 +
.../java/org/apache/tajo/storage/VTuple.java | 6 +
.../tajo/storage/parquet/ParquetAppender.java | 11 +-
.../tajo/storage/parquet/TestReadWrite.java | 7 +-
tajo-thirdparty/asm/pom.xml | 180 ++
.../org/objectweb/asm/AnnotationVisitor.java | 169 ++
.../org/objectweb/asm/AnnotationWriter.java | 318 +++
.../tajo/org/objectweb/asm/Attribute.java | 255 ++
.../tajo/org/objectweb/asm/ByteVector.java | 312 ++
.../tajo/org/objectweb/asm/ClassReader.java | 2202 ++++++++++++++
.../tajo/org/objectweb/asm/ClassVisitor.java | 286 ++
.../tajo/org/objectweb/asm/ClassWriter.java | 1706 +++++++++++
.../apache/tajo/org/objectweb/asm/Context.java | 110 +
.../org/apache/tajo/org/objectweb/asm/Edge.java | 75 +
.../tajo/org/objectweb/asm/FieldVisitor.java | 121 +
.../tajo/org/objectweb/asm/FieldWriter.java | 273 ++
.../apache/tajo/org/objectweb/asm/Frame.java | 1453 ++++++++++
.../apache/tajo/org/objectweb/asm/Handle.java | 170 ++
.../apache/tajo/org/objectweb/asm/Handler.java | 121 +
.../org/apache/tajo/org/objectweb/asm/Item.java | 311 ++
.../apache/tajo/org/objectweb/asm/Label.java | 560 ++++
.../tajo/org/objectweb/asm/MethodVisitor.java | 662 +++++
.../tajo/org/objectweb/asm/MethodWriter.java | 2685 ++++++++++++++++++
.../apache/tajo/org/objectweb/asm/Opcodes.java | 358 +++
.../org/apache/tajo/org/objectweb/asm/Type.java | 895 ++++++
.../tajo/org/objectweb/asm/attrs/package.html | 66 +
.../objectweb/asm/commons/AdviceAdapter.java | 625 ++++
.../objectweb/asm/commons/AnalyzerAdapter.java | 920 ++++++
.../asm/commons/CodeSizeEvaluator.java | 217 ++
.../objectweb/asm/commons/GeneratorAdapter.java | 1641 +++++++++++
.../asm/commons/InstructionAdapter.java | 1090 +++++++
.../asm/commons/JSRInlinerAdapter.java | 746 +++++
.../asm/commons/LocalVariablesSorter.java | 361 +++
.../tajo/org/objectweb/asm/commons/Method.java | 282 ++
.../org/objectweb/asm/commons/Remapper.java | 223 ++
.../asm/commons/RemappingAnnotationAdapter.java | 79 +
.../asm/commons/RemappingClassAdapter.java | 126 +
.../asm/commons/RemappingFieldAdapter.java | 62 +
.../asm/commons/RemappingMethodAdapter.java | 161 ++
.../asm/commons/RemappingSignatureAdapter.java | 155 +
.../asm/commons/SerialVersionUIDAdder.java | 533 ++++
.../objectweb/asm/commons/SimpleRemapper.java | 69 +
.../objectweb/asm/commons/StaticInitMerger.java | 96 +
.../asm/commons/TableSwitchGenerator.java | 57 +
.../asm/commons/TryCatchBlockSorter.java | 92 +
.../tajo/org/objectweb/asm/commons/package.html | 66 +
.../optimizer/AnnotationConstantsCollector.java | 147 +
.../asm/optimizer/ClassConstantsCollector.java | 184 ++
.../objectweb/asm/optimizer/ClassOptimizer.java | 167 ++
.../org/objectweb/asm/optimizer/Constant.java | 323 +++
.../objectweb/asm/optimizer/ConstantPool.java | 249 ++
.../asm/optimizer/FieldConstantsCollector.java | 75 +
.../objectweb/asm/optimizer/JarOptimizer.java | 234 ++
.../asm/optimizer/MethodConstantsCollector.java | 161 ++
.../asm/optimizer/MethodOptimizer.java | 167 ++
.../objectweb/asm/optimizer/NameMapping.java | 114 +
.../org/objectweb/asm/optimizer/Shrinker.java | 283 ++
.../objectweb/asm/optimizer/jdk1.2.2_017.txt.gz | Bin 0 -> 113814 bytes
.../objectweb/asm/optimizer/jdk1.3.1_19.txt.gz | Bin 0 -> 128067 bytes
.../asm/optimizer/shrink-annotations.properties | 71 +
.../asm/optimizer/shrink-frames.properties | 80 +
.../asm/optimizer/shrink-resize.properties | 55 +
.../asm/optimizer/shrink-signatures.properties | 61 +
.../asm/optimizer/shrink-writer.properties | 84 +
.../objectweb/asm/optimizer/shrink.properties | 372 +++
.../apache/tajo/org/objectweb/asm/package.html | 105 +
.../asm/signature/SignatureReader.java | 228 ++
.../asm/signature/SignatureVisitor.java | 235 ++
.../asm/signature/SignatureWriter.java | 227 ++
.../org/objectweb/asm/signature/package.html | 54 +
.../objectweb/asm/tree/AbstractInsnNode.java | 248 ++
.../org/objectweb/asm/tree/AnnotationNode.java | 225 ++
.../tajo/org/objectweb/asm/tree/ClassNode.java | 345 +++
.../org/objectweb/asm/tree/FieldInsnNode.java | 108 +
.../tajo/org/objectweb/asm/tree/FieldNode.java | 243 ++
.../tajo/org/objectweb/asm/tree/FrameNode.java | 210 ++
.../org/objectweb/asm/tree/IincInsnNode.java | 82 +
.../org/objectweb/asm/tree/InnerClassNode.java | 101 +
.../tajo/org/objectweb/asm/tree/InsnList.java | 600 ++++
.../tajo/org/objectweb/asm/tree/InsnNode.java | 87 +
.../org/objectweb/asm/tree/IntInsnNode.java | 87 +
.../asm/tree/InvokeDynamicInsnNode.java | 100 +
.../org/objectweb/asm/tree/JumpInsnNode.java | 95 +
.../tajo/org/objectweb/asm/tree/LabelNode.java | 78 +
.../org/objectweb/asm/tree/LdcInsnNode.java | 78 +
.../org/objectweb/asm/tree/LineNumberNode.java | 84 +
.../objectweb/asm/tree/LocalVariableNode.java | 112 +
.../asm/tree/LookupSwitchInsnNode.java | 117 +
.../org/objectweb/asm/tree/MethodInsnNode.java | 109 +
.../tajo/org/objectweb/asm/tree/MethodNode.java | 597 ++++
.../asm/tree/MultiANewArrayInsnNode.java | 83 +
.../objectweb/asm/tree/TableSwitchInsnNode.java | 113 +
.../objectweb/asm/tree/TryCatchBlockNode.java | 94 +
.../org/objectweb/asm/tree/TypeInsnNode.java | 90 +
.../org/objectweb/asm/tree/VarInsnNode.java | 93 +
.../objectweb/asm/tree/analysis/Analyzer.java | 549 ++++
.../asm/tree/analysis/AnalyzerException.java | 61 +
.../asm/tree/analysis/BasicInterpreter.java | 358 +++
.../objectweb/asm/tree/analysis/BasicValue.java | 111 +
.../asm/tree/analysis/BasicVerifier.java | 433 +++
.../org/objectweb/asm/tree/analysis/Frame.java | 729 +++++
.../asm/tree/analysis/Interpreter.java | 226 ++
.../asm/tree/analysis/SimpleVerifier.java | 320 +++
.../objectweb/asm/tree/analysis/SmallSet.java | 134 +
.../asm/tree/analysis/SourceInterpreter.java | 198 ++
.../asm/tree/analysis/SourceValue.java | 97 +
.../objectweb/asm/tree/analysis/Subroutine.java | 90 +
.../org/objectweb/asm/tree/analysis/Value.java | 45 +
.../objectweb/asm/tree/analysis/package.html | 85 +
.../tajo/org/objectweb/asm/tree/package.html | 210 ++
.../tajo/org/objectweb/asm/util/ASMifiable.java | 56 +
.../tajo/org/objectweb/asm/util/ASMifier.java | 1151 ++++++++
.../asm/util/CheckAnnotationAdapter.java | 136 +
.../objectweb/asm/util/CheckClassAdapter.java | 914 ++++++
.../objectweb/asm/util/CheckFieldAdapter.java | 100 +
.../objectweb/asm/util/CheckMethodAdapter.java | 1397 +++++++++
.../asm/util/CheckSignatureAdapter.java | 330 +++
.../tajo/org/objectweb/asm/util/Printer.java | 500 ++++
.../org/objectweb/asm/util/Textifiable.java | 56 +
.../tajo/org/objectweb/asm/util/Textifier.java | 1200 ++++++++
.../asm/util/TraceAnnotationVisitor.java | 89 +
.../objectweb/asm/util/TraceClassVisitor.java | 209 ++
.../objectweb/asm/util/TraceFieldVisitor.java | 76 +
.../objectweb/asm/util/TraceMethodVisitor.java | 223 ++
.../asm/util/TraceSignatureVisitor.java | 317 +++
.../tajo/org/objectweb/asm/util/package.html | 58 +
.../objectweb/asm/xml/ASMContentHandler.java | 1317 +++++++++
.../tajo/org/objectweb/asm/xml/Processor.java | 1044 +++++++
.../tajo/org/objectweb/asm/xml/SAXAdapter.java | 89 +
.../objectweb/asm/xml/SAXAnnotationAdapter.java | 185 ++
.../org/objectweb/asm/xml/SAXClassAdapter.java | 324 +++
.../org/objectweb/asm/xml/SAXCodeAdapter.java | 362 +++
.../org/objectweb/asm/xml/SAXFieldAdapter.java | 63 +
.../tajo/org/objectweb/asm/xml/asm-xml.dtd | 367 +++
.../tajo/org/objectweb/asm/xml/package.html | 114 +
tajo-yarn-pullserver/pom.xml | 17 +
.../java/org/apache/tajo/storage/Tuple.java | 27 +-
256 files changed, 47500 insertions(+), 308 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index f2798b4..2b5f149 100644
--- a/CHANGES
+++ b/CHANGES
@@ -31,6 +31,9 @@ Release 0.9.0 - unreleased
IMPROVEMENT
+ TAJO-906: Runtime code generation for evaluating expression trees.
+ (hyunsik)
+
TAJO-931: Output file can be punctuated depending on the file size.
(hyunsik)
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
index 86975d5..ca54d5e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -340,3 +340,34 @@ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+-----------------------------------------------------------------------------
+Copyright (c) 2000-2011 INRIA, France Telecom
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holders nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGE.
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index bf33c69..d7361bd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,6 +90,7 @@
<module>tajo-storage</module>
<module>tajo-yarn-pullserver</module>
<module>tajo-dist</module>
+ <module>tajo-thirdparty/asm</module>
</modules>
<build>
@@ -178,9 +179,9 @@
</executions>
</plugin>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-pmd-plugin</artifactId>
- <version>2.7.1</version>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>0.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -336,51 +337,6 @@
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
- <version>0.8</version>
- <executions>
- <execution>
- <phase>verify</phase>
- <goals>
- <goal>check</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <excludeSubProjects>false</excludeSubProjects>
- <numUnapprovedLicenses>0</numUnapprovedLicenses>
- <excludes>
- <exclude>CHANGES</exclude>
- <exclude>**/workers</exclude>
- <exclude>**/querymasters</exclude>
- <exclude>**/*.sql</exclude>
- <exclude>**/*.hiveql</exclude>
- <exclude>**/*.schema</exclude>
- <exclude>**/*.tbl</exclude>
- <exclude>**/*.js</exclude>
- <exclude>**/*.result</exclude>
- <exclude>**/*.json</exclude>
- <exclude>**/*.avsc</exclude>
- <!-- generated content -->
- <exclude>**/target/**</exclude>
- <exclude>**/*.log</exclude>
- <!-- source control and IDEs -->
- <exclude>.git/**</exclude>
- <exclude>.gitignore</exclude>
- <exclude>*.patch</exclude>
- <exclude>.idea/**</exclude>
- <exclude>**/*.iml</exclude>
- <exclude>**/*.ipr</exclude>
- <exclude>**/.project</exclude>
- <exclude>**/.classpath</exclude>
- <exclude>**/.settings/**</exclude>
- <exclude>atlassian-ide-plugin.xml</exclude>
- <exclude>.reviewboardrc</exclude>
- <exclude>**/sphinx_rtd_theme/**/*</exclude>
- <!-- tajo-doc -->
- <exclude>**/*.rst</exclude>
- <exclude>**/resources/*</exclude>
- </excludes>
- </configuration>
</plugin>
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-algebra/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-algebra/pom.xml b/tajo-algebra/pom.xml
index e8ff2bc..a49c212 100644
--- a/tajo-algebra/pom.xml
+++ b/tajo-algebra/pom.xml
@@ -44,6 +44,18 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
@@ -79,7 +91,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-catalog/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-catalog/pom.xml b/tajo-catalog/pom.xml
index e3ae9df..970959a 100644
--- a/tajo-catalog/pom.xml
+++ b/tajo-catalog/pom.xml
@@ -45,9 +45,12 @@
<build>
<plugins>
<plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
@@ -55,12 +58,6 @@
<skip>true</skip>
</configuration>
</plugin>
- <plugin>
- <groupId>org.apache.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <configuration>
- </configuration>
- </plugin>
</plugins>
</build>
@@ -163,7 +160,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
</plugins>
</reporting>
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-catalog/tajo-catalog-client/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-client/pom.xml b/tajo-catalog/tajo-catalog-client/pom.xml
index 959eb4c..4db1c26 100644
--- a/tajo-catalog/tajo-catalog-client/pom.xml
+++ b/tajo-catalog/tajo-catalog-client/pom.xml
@@ -47,6 +47,18 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
@@ -110,7 +122,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-catalog/tajo-catalog-common/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/pom.xml b/tajo-catalog/tajo-catalog-common/pom.xml
index 34f2f4b..b82495f 100644
--- a/tajo-catalog/tajo-catalog-common/pom.xml
+++ b/tajo-catalog/tajo-catalog-common/pom.xml
@@ -47,6 +47,18 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
@@ -129,7 +141,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
index ae00084..a2d9796 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
@@ -481,7 +481,7 @@ public class CatalogUtil {
// If all parameters are equivalent to the basis type
for (TajoDataTypes.Type type : varLengthTypesOfGivenParams) {
- if (type != Type.NULL_TYPE && type != basisTypeOfVarLengthType) {
+ if (type != Type.NULL_TYPE && !isCompatibleType(basisTypeOfVarLengthType, type)) {
return false;
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/FunctionDesc.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/FunctionDesc.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/FunctionDesc.java
index bed4f08..3d9bc99 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/FunctionDesc.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/FunctionDesc.java
@@ -98,7 +98,7 @@ public class FunctionDesc implements ProtoObject<FunctionDescProto>, Cloneable,
}
@SuppressWarnings("unchecked")
- public Class<? extends Function> getFuncClass() throws InternalException {
+ public Class<? extends Function> getFuncClass() {
return this.funcClass;
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-catalog/tajo-catalog-drivers/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-drivers/pom.xml b/tajo-catalog/tajo-catalog-drivers/pom.xml
index b57967b..2cb05ee 100644
--- a/tajo-catalog/tajo-catalog-drivers/pom.xml
+++ b/tajo-catalog/tajo-catalog-drivers/pom.xml
@@ -38,9 +38,17 @@
<build>
<plugins>
<plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>tajo-hcatalog/**</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
@@ -68,7 +76,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
</plugins>
</reporting>
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/pom.xml b/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/pom.xml
index bac9d27..02ea16b 100644
--- a/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/pom.xml
+++ b/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/pom.xml
@@ -47,6 +47,23 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <excludes>
+ <exclude>derby.log</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
@@ -69,7 +86,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
</plugins>
</build>
@@ -371,7 +387,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
</plugins>
</reporting>
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-catalog/tajo-catalog-server/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/pom.xml b/tajo-catalog/tajo-catalog-server/pom.xml
index a6812fc..1e9e2c2 100644
--- a/tajo-catalog/tajo-catalog-server/pom.xml
+++ b/tajo-catalog/tajo-catalog-server/pom.xml
@@ -47,6 +47,24 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <excludes>
+ <exclude>derby.log</exclude>
+ <exclude>src/main/resources/schemas/**/*.sql</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
@@ -106,7 +124,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
</plugins>
</build>
@@ -217,7 +234,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
</plugins>
</reporting>
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-client/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-client/pom.xml b/tajo-client/pom.xml
index 0002a68..1c109f5 100644
--- a/tajo-client/pom.xml
+++ b/tajo-client/pom.xml
@@ -58,9 +58,20 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.12.4</version>
<configuration>
<systemProperties>
<tajo.test>TRUE</tajo.test>
@@ -332,7 +343,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
</plugins>
</reporting>
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-common/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-common/pom.xml b/tajo-common/pom.xml
index da2a7d0..f1a8c40 100644
--- a/tajo-common/pom.xml
+++ b/tajo-common/pom.xml
@@ -100,6 +100,18 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
@@ -319,7 +331,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.15</version>
</plugin>
</plugins>
</reporting>
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/SessionVars.java b/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
index 5503aaa..c32fd43 100644
--- a/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
+++ b/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
@@ -108,8 +108,8 @@ public enum SessionVars implements ConfigKey {
HASH_GROUPBY_SIZE_LIMIT(ConfVars.$EXECUTOR_GROUPBY_INMEMORY_HASH_THRESHOLD, "limited size for hash groupby (mb)",
DEFAULT),
MAX_OUTPUT_FILE_SIZE(ConfVars.$MAX_OUTPUT_FILE_SIZE, "Maximum per-output file size (mb). 0 means infinite.", DEFAULT),
-
NULL_CHAR(ConfVars.$CSVFILE_NULL, "null char of text file output", DEFAULT),
+ CODEGEN(ConfVars.$CODEGEN, "Runtime code generation enabled (experiment)", DEFAULT),
// Behavior Control ---------------------------------------------------------
ARITHABORT(ConfVars.$BEHAVIOR_ARITHMETIC_ABORT,
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
index 77c2363..178d80e 100644
--- a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
+++ b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
@@ -324,7 +324,7 @@ public class TajoConf extends Configuration {
$EXECUTOR_GROUPBY_INMEMORY_HASH_THRESHOLD("tajo.executor.groupby.in-memory-hash-threshold-bytes",
(long)256 * 1048576),
$MAX_OUTPUT_FILE_SIZE("tajo.query.max-outfile-size-mb", 0), // zero means infinite
-
+ $CODEGEN("tajo.executor.codegen.enabled", false), // Runtime code generation
// Client -----------------------------------------------------------------
$CLIENT_SESSION_EXPIRY_TIME("tajo.client.session.expiry-time-sec", 3600), // default time is one hour.
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-common/src/main/java/org/apache/tajo/datum/CharDatum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/CharDatum.java b/tajo-common/src/main/java/org/apache/tajo/datum/CharDatum.java
index e6c4d94..750930f 100644
--- a/tajo-common/src/main/java/org/apache/tajo/datum/CharDatum.java
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/CharDatum.java
@@ -149,9 +149,8 @@ public class CharDatum extends Datum {
public int compareTo(Datum datum) {
switch (datum.type()) {
case CHAR:
- CharDatum other = (CharDatum) datum;
- return UnsignedBytes.lexicographicalComparator().compare(bytes, other.bytes);
-
+ case TEXT:
+ return UnsignedBytes.lexicographicalComparator().compare(bytes, datum.asByteArray());
case NULL_TYPE:
return -1;
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-common/src/main/java/org/apache/tajo/datum/Datum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/Datum.java b/tajo-common/src/main/java/org/apache/tajo/datum/Datum.java
index 29d7a04..442db71 100644
--- a/tajo-common/src/main/java/org/apache/tajo/datum/Datum.java
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/Datum.java
@@ -53,6 +53,10 @@ public abstract class Datum implements Comparable<Datum>, GsonObject {
return false;
}
+ public boolean isNotNull() {
+ return true;
+ }
+
public boolean asBool() {
throw new InvalidCastException(type, Type.BOOLEAN);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java b/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java
index 7d6ef18..17cfc7a 100644
--- a/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java
@@ -271,17 +271,15 @@ public class DatumFactory {
}
public static DateDatum createDate(String dateStr) {
- TimeMeta tm = DateTimeUtil.decodeDateTime(dateStr);
- return new DateDatum(DateTimeUtil.date2j(tm.years, tm.monthOfYear, tm.dayOfMonth));
+ return new DateDatum(DateTimeUtil.toJulianDate(dateStr));
}
public static TimeDatum createTime(long instance) {
return new TimeDatum(instance);
}
- public static TimeDatum createTime(String dateStr) {
- TimeMeta tm = DateTimeUtil.decodeDateTime(dateStr);
- return new TimeDatum(DateTimeUtil.toTime(tm));
+ public static TimeDatum createTime(String timeStr) {
+ return new TimeDatum(DateTimeUtil.toJulianTime(timeStr));
}
public static TimestampDatum createTimestmpDatumWithJavaMillis(long millis) {
@@ -300,6 +298,11 @@ public class DatumFactory {
return new IntervalDatum(intervalStr);
}
+ @SuppressWarnings("unused")
+ public static IntervalDatum createInterval(long interval) {
+ return new IntervalDatum(interval);
+ }
+
public static DateDatum createDate(Datum datum) {
switch (datum.type()) {
case INT4:
@@ -333,11 +336,7 @@ public class DatumFactory {
public static TimestampDatum createTimestamp(Datum datum) {
switch (datum.type()) {
case TEXT:
- long timestamp = DateTimeUtil.toJulianTimestamp(datum.asChars());
- TimeMeta tm = new TimeMeta();
- DateTimeUtil.toJulianTimeMeta(timestamp, tm);
- DateTimeUtil.toUTCTimezone(tm);
- return new TimestampDatum(DateTimeUtil.toJulianTimestamp(tm));
+ return parseTimestamp(datum.asChars());
case TIMESTAMP:
return (TimestampDatum) datum;
default:
@@ -345,6 +344,15 @@ public class DatumFactory {
}
}
+ @SuppressWarnings("unused")
+ public static TimestampDatum createTimestamp(long julianTimestamp) {
+ return new TimestampDatum(julianTimestamp);
+ }
+
+ public static TimestampDatum parseTimestamp(String str) {
+ return new TimestampDatum(DateTimeUtil.toJulianTimestampWithTZ(str));
+ }
+
public static BlobDatum createBlob(byte[] val) {
return new BlobDatum(val);
}
@@ -357,6 +365,10 @@ public class DatumFactory {
return new BlobDatum(val.getBytes());
}
+ public static Inet4Datum createInet4(int encoded) {
+ return new Inet4Datum(encoded);
+ }
+
public static Inet4Datum createInet4(byte[] val) {
return new Inet4Datum(val);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-common/src/main/java/org/apache/tajo/datum/Inet4Datum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/Inet4Datum.java b/tajo-common/src/main/java/org/apache/tajo/datum/Inet4Datum.java
index 08b76f0..1de81cd 100644
--- a/tajo-common/src/main/java/org/apache/tajo/datum/Inet4Datum.java
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/Inet4Datum.java
@@ -29,6 +29,11 @@ public class Inet4Datum extends Datum {
private static final int size = 4;
@Expose private final int address;
+ Inet4Datum(int encoded) {
+ super(Type.INET4);
+ this.address = encoded;
+ }
+
public Inet4Datum(String addr) {
super(Type.INET4);
String [] elems = addr.split("\\.");
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-common/src/main/java/org/apache/tajo/datum/NullDatum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/NullDatum.java b/tajo-common/src/main/java/org/apache/tajo/datum/NullDatum.java
index 532e7cd..0007b52 100644
--- a/tajo-common/src/main/java/org/apache/tajo/datum/NullDatum.java
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/NullDatum.java
@@ -52,6 +52,11 @@ public class NullDatum extends Datum {
}
@Override
+ public boolean isNotNull() {
+ return false;
+ }
+
+ @Override
public boolean asBool() {
throw new InvalidCastException(Type.NULL_TYPE, Type.BOOLEAN);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-common/src/main/java/org/apache/tajo/util/CommonTestingUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/CommonTestingUtil.java b/tajo-common/src/main/java/org/apache/tajo/util/CommonTestingUtil.java
index 8dd8bfe..e62cb12 100644
--- a/tajo-common/src/main/java/org/apache/tajo/util/CommonTestingUtil.java
+++ b/tajo-common/src/main/java/org/apache/tajo/util/CommonTestingUtil.java
@@ -21,12 +21,34 @@ package org.apache.tajo.util;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
+import org.apache.tajo.ConfigKey;
+import org.apache.tajo.OverridableConf;
+import org.apache.tajo.SessionVars;
+import org.apache.tajo.conf.TajoConf;
import java.io.IOException;
import java.util.UUID;
public class CommonTestingUtil {
- public static final String TAJO_TEST = "tajo.test";
+ public static final String TAJO_TEST_KEY = "tajo.test.enabled";
+ public static final String TAJO_TEST_TRUE = "true";
+ private static OverridableConf userSessionVars;
+
+ static {
+ System.setProperty(CommonTestingUtil.TAJO_TEST_KEY, CommonTestingUtil.TAJO_TEST_TRUE);
+
+ userSessionVars = new OverridableConf(new TajoConf(), ConfigKey.ConfigType.SESSION);
+ for (SessionVars var : SessionVars.values()) {
+ String value = System.getProperty(var.keyname());
+ if (value != null) {
+ userSessionVars.put(var, value);
+ }
+ }
+ }
+
+ public static OverridableConf getSessionVarsForTest() {
+ return userSessionVars;
+ }
/**
*
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-common/src/main/java/org/apache/tajo/util/Pair.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/Pair.java b/tajo-common/src/main/java/org/apache/tajo/util/Pair.java
index 7b5f8ad..e8852df 100644
--- a/tajo-common/src/main/java/org/apache/tajo/util/Pair.java
+++ b/tajo-common/src/main/java/org/apache/tajo/util/Pair.java
@@ -18,6 +18,8 @@
package org.apache.tajo.util;
+import com.google.common.base.Objects;
+
public class Pair<T1, T2> {
private T1 first;
private T2 second;
@@ -49,7 +51,17 @@ public class Pair<T1, T2> {
}
@Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Pair) {
+ Pair other = (Pair) obj;
+ return first.equals(other.first) && second.equals(other.second);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
public int hashCode() {
- return toString().hashCode();
+ return Objects.hashCode(first, second);
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-common/src/main/java/org/apache/tajo/util/datetime/DateTimeUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/datetime/DateTimeUtil.java b/tajo-common/src/main/java/org/apache/tajo/util/datetime/DateTimeUtil.java
index 327b423..9198f5b 100644
--- a/tajo-common/src/main/java/org/apache/tajo/util/datetime/DateTimeUtil.java
+++ b/tajo-common/src/main/java/org/apache/tajo/util/datetime/DateTimeUtil.java
@@ -663,6 +663,41 @@ public class DateTimeUtil {
return toJulianTimestamp(tm);
}
+
+ /**
+ * Parse datetime string to julian time.
+ * The result is the local time basis.
+ * @param timestampStr
+ * @return
+ */
+ public static long toJulianTimestampWithTZ(String timestampStr) {
+ long timestamp = DateTimeUtil.toJulianTimestamp(timestampStr);
+ TimeMeta tm = new TimeMeta();
+ DateTimeUtil.toJulianTimeMeta(timestamp, tm);
+ DateTimeUtil.toUTCTimezone(tm);
+ return DateTimeUtil.toJulianTimestamp(tm);
+ }
+
+ /**
+ * Parse datetime string to julian date.
+ * @param dateStr
+ * @return
+ */
+ public static int toJulianDate(String dateStr) {
+ TimeMeta tm = DateTimeUtil.decodeDateTime(dateStr);
+ return DateTimeUtil.date2j(tm.years, tm.monthOfYear, tm.dayOfMonth);
+ }
+
+ /**
+ * Parse datetime string to julian time.
+ * @param timeStr
+ * @return
+ */
+ public static long toJulianTime(String timeStr) {
+ TimeMeta tm = DateTimeUtil.decodeDateTime(timeStr);
+ return DateTimeUtil.toTime(tm);
+ }
+
public static TimeMeta decodeDateTime(String str) {
return decodeDateTime(str, MAXDATEFIELDS);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-core/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-core/pom.xml b/tajo-core/pom.xml
index 364c428..d33b598 100644
--- a/tajo-core/pom.xml
+++ b/tajo-core/pom.xml
@@ -60,9 +60,32 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <excludes>
+ <exclude>derby.log</exclude>
+ <exclude>benchmark/**</exclude>
+ <exclude>src/test/tpch/**</exclude>
+ <exclude>src/test/resources/dataset/**</exclude>
+ <exclude>src/test/resources/queries/**</exclude>
+ <exclude>src/test/resources/results/**</exclude>
+ <exclude>src/test/resources/results/**</exclude>
+ <exclude>src/main/resources/webapps/static/js/*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.12.4</version>
<configuration>
<systemProperties>
<tajo.test>TRUE</tajo.test>
@@ -192,11 +215,6 @@
</execution>
</executions>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-pmd-plugin</artifactId>
- <version>2.7.1</version>
- </plugin>
</plugins>
</build>
@@ -242,6 +260,10 @@
<groupId>org.apache.tajo</groupId>
<artifactId>tajo-rpc</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.tajo</groupId>
+ <artifactId>tajo-thirdparty-asm</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CaseWhenEmitter.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CaseWhenEmitter.java b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CaseWhenEmitter.java
new file mode 100644
index 0000000..16bd396
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CaseWhenEmitter.java
@@ -0,0 +1,210 @@
+/*
+ * 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.tajo.engine.codegen;
+
+import com.google.common.base.Preconditions;
+import org.apache.tajo.engine.eval.BinaryEval;
+import org.apache.tajo.engine.eval.CaseWhenEval;
+import org.apache.tajo.engine.eval.EvalNode;
+import org.apache.tajo.engine.eval.EvalType;
+import org.apache.tajo.org.objectweb.asm.Label;
+import org.apache.tajo.org.objectweb.asm.Opcodes;
+
+import java.util.List;
+import java.util.Stack;
+
+class CaseWhenEmitter implements EvalCodeEmitter<CaseWhenEval> {
+ public static final CaseWhenEmitter instance;
+
+ static {
+ instance = new CaseWhenEmitter();
+ }
+
+ public static CaseWhenEmitter getInstance() {
+ return instance;
+ }
+
+ @Override
+ public void emit(EvalCodeGenerator codeGen, EvalCodeGenContext context, CaseWhenEval caseWhen,
+ Stack<EvalNode> stack) {
+ // TYPE 1: CASE <expr> WHEN x THEN c1 WHEN y THEN c2 WHEN c3 ELSE ... END;
+ EvalNode commonTerm = extractCommonTerm(caseWhen.getIfThenEvals());
+
+ if (commonTerm != null) {
+ int casesNum = caseWhen.getIfThenEvals().size();
+ List<CaseWhenEval.IfThenEval> ifThenList = caseWhen.getIfThenEvals();
+ TajoGeneratorAdapter.SwitchCase[] cases = new TajoGeneratorAdapter.SwitchCase[casesNum];
+
+ for (int i = 0; i < caseWhen.getIfThenEvals().size(); i++) {
+ int key = getSwitchIndex(ifThenList.get(i).getCondition());
+ EvalNode result = ifThenList.get(i).getResult();
+ cases[i] = new TajoGeneratorAdapter.SwitchCase(key, result);
+ }
+ CaseWhenSwitchGenerator gen = new CaseWhenSwitchGenerator(codeGen, context, stack, cases, caseWhen.getElse());
+
+ stack.push(caseWhen);
+
+ codeGen.visit(context, commonTerm, stack);
+
+ Label ifNull = context.newLabel();
+ Label endIf = context.newLabel();
+
+ context.emitNullityCheck(ifNull);
+ context.generatorAdapter.tableSwitch(gen.keys(), gen);
+ context.gotoLabel(endIf);
+
+ codeGen.emitLabel(context, ifNull);
+ context.pop(commonTerm.getValueType());
+ codeGen.visit(context, caseWhen.getElse(), stack);
+
+ codeGen.emitLabel(context, endIf);
+
+ stack.pop();
+ } else { // TYPE 2: CASE WHEN x = c1 THEN r1 WHEN y = c2 THEN r2 ELSE ... END
+ int casesNum = caseWhen.getIfThenEvals().size();
+ Label [] labels = new Label[casesNum - 1];
+
+ for (int i = 0; i < labels.length; i++) {
+ labels[i] = context.newLabel();
+ }
+
+ Label defaultLabel = context.newLabel();
+ Label ifNull = context.newLabel();
+ Label afterAll = context.newLabel();
+
+ // The following will generate code as follows. defaultLabel points to the last else clause.
+ //
+ // if (...) {
+ // .....
+ // } else if (...) {
+ // ....
+ // } else if (...) {
+ // } ..... {
+ // } else { <- default label
+ // ...
+ // }
+
+ stack.push(caseWhen);
+ for (int i = 0; i < casesNum; i++) {
+ CaseWhenEval.IfThenEval ifThenEval = caseWhen.getIfThenEvals().get(i);
+
+ stack.push(caseWhen);
+ codeGen.visit(context, ifThenEval.getCondition(), stack);
+ int NULL_FLAG = context.istore();
+ int CHILD = context.store(ifThenEval.getCondition().getValueType());
+
+ context.iload(NULL_FLAG);
+ context.emitNullityCheck(ifNull);
+
+ context.pushBooleanOfThreeValuedLogic(true);
+ context.load(ifThenEval.getCondition().getValueType(), CHILD);
+ context.methodvisitor.visitJumpInsn(Opcodes.IF_ICMPNE, (casesNum - 1) < i ? labels[i] : defaultLabel); // false
+
+ codeGen.visit(context, ifThenEval.getResult(), stack);
+ context.gotoLabel(afterAll);
+ stack.pop();
+
+ if (i < casesNum - 1) {
+ codeGen.emitLabel(context, labels[i]); // else if
+ }
+ }
+ stack.pop();
+
+ codeGen.emitLabel(context, defaultLabel);
+ if (caseWhen.hasElse()) {
+ stack.push(caseWhen);
+ codeGen.visit(context, caseWhen.getElse(), stack);
+ stack.pop();
+ context.gotoLabel(afterAll);
+ } else {
+ context.gotoLabel(ifNull);
+ }
+
+ codeGen.emitLabel(context, ifNull);
+ context.pushDummyValue(caseWhen.getValueType());
+ context.pushNullFlag(false);
+
+ codeGen.emitLabel(context, afterAll);
+ }
+ }
+
+ private EvalNode extractCommonTerm(List<CaseWhenEval.IfThenEval> ifThenEvals) {
+ EvalNode commonTerm = null;
+
+ for (int i = 0; i < ifThenEvals.size(); i++) {
+ EvalNode predicate = ifThenEvals.get(i).getCondition();
+ if (!checkIfSimplePredicate(predicate)) {
+ return null;
+ }
+
+ BinaryEval bin = (BinaryEval) predicate;
+
+ EvalNode baseTerm;
+ if (bin.getLeftExpr().getType() == EvalType.CONST) {
+ baseTerm = bin.getRightExpr();
+ } else {
+ baseTerm = bin.getLeftExpr();
+ }
+
+ if (commonTerm == null) {
+ commonTerm = baseTerm;
+ } else {
+ if (!baseTerm.equals(commonTerm)) {
+ return null;
+ }
+ }
+ }
+
+ return commonTerm;
+ }
+
+ /**
+ * Simple predicate means one term is constant and comparator is equal.
+ *
+ * @param predicate Predicate to be checked
+ * @return True if the predicate is a simple form.
+ */
+ private boolean checkIfSimplePredicate(EvalNode predicate) {
+ if (predicate.getType() == EvalType.EQUAL) {
+ BinaryEval binaryEval = (BinaryEval) predicate;
+ EvalNode lhs = binaryEval.getLeftExpr();
+ EvalNode rhs = binaryEval.getRightExpr();
+
+ boolean simple = false;
+ simple |= rhs.getType() == EvalType.CONST && TajoGeneratorAdapter.isJVMInternalInt(rhs.getValueType());
+ simple |= lhs.getType() == EvalType.CONST && TajoGeneratorAdapter.isJVMInternalInt(lhs.getValueType());
+ return simple;
+ } else {
+ return false;
+ }
+ }
+
+ private int getSwitchIndex(EvalNode predicate) {
+ Preconditions.checkArgument(checkIfSimplePredicate(predicate),
+ "This expression cannot be used for switch table: " + predicate);
+
+ BinaryEval bin = (BinaryEval) predicate;
+
+ if (bin.getLeftExpr().getType() == EvalType.CONST) {
+ return bin.getLeftExpr().eval(null, null).asInt4();
+ } else {
+ return bin.getRightExpr().eval(null, null).asInt4();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CaseWhenSwitchGenerator.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CaseWhenSwitchGenerator.java b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CaseWhenSwitchGenerator.java
new file mode 100644
index 0000000..6f928ac
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CaseWhenSwitchGenerator.java
@@ -0,0 +1,92 @@
+/*
+ * 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.tajo.engine.codegen;
+
+import com.google.common.collect.Maps;
+import org.apache.tajo.engine.eval.EvalNode;
+import org.apache.tajo.org.objectweb.asm.Label;
+
+import java.util.NavigableMap;
+import java.util.Stack;
+
+class CaseWhenSwitchGenerator implements TajoGeneratorAdapter.SwitchCaseGenerator {
+ final private EvalCodeGenerator generator;
+ final private EvalCodeGenContext context;
+ final private Stack<EvalNode> stack;
+
+ final NavigableMap<Integer, TajoGeneratorAdapter.SwitchCase> casesMap;
+ final EvalNode defaultEval;
+
+ public CaseWhenSwitchGenerator(EvalCodeGenerator generator, EvalCodeGenContext context, Stack<EvalNode> stack,
+ TajoGeneratorAdapter.SwitchCase[] cases, EvalNode defaultEval) {
+ this.generator = generator;
+ this.context = context;
+ this.stack = stack;
+ this.casesMap = Maps.newTreeMap();
+ for (TajoGeneratorAdapter.SwitchCase switchCase : cases) {
+ this.casesMap.put(switchCase.key(), switchCase);
+ }
+ this.defaultEval = defaultEval;
+ }
+
+ @Override
+ public int size() {
+ return casesMap.size();
+ }
+
+ @Override
+ public int min() {
+ return casesMap.firstEntry().getKey();
+ }
+
+ @Override
+ public int max() {
+ return casesMap.lastEntry().getKey();
+ }
+
+ @Override
+ public int key(int index) {
+ return casesMap.get(index).key();
+ }
+
+ @Override
+ public void generateCase(int key, Label end) {
+ generator.visit(context, casesMap.get(key).result(), stack);
+ context.gotoLabel(end);
+ }
+
+ public int [] keys() {
+ int [] keys = new int[casesMap.size()];
+
+ int idx = 0;
+ for (int key : casesMap.keySet()) {
+ keys[idx++] = key;
+ }
+ return keys;
+ }
+
+ public void generateDefault() {
+ if (defaultEval != null) {
+ generator.visit(context, defaultEval, stack);
+ } else {
+ context.pushNullOfThreeValuedLogic();
+ context.pushNullFlag(false);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CodeGenUtils.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CodeGenUtils.java b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CodeGenUtils.java
new file mode 100644
index 0000000..84a93fc
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CodeGenUtils.java
@@ -0,0 +1,41 @@
+/*
+ * 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.tajo.engine.codegen;
+
+import org.apache.tajo.org.objectweb.asm.ClassReader;
+import org.apache.tajo.org.objectweb.asm.util.ASMifier;
+import org.apache.tajo.org.objectweb.asm.util.TraceClassVisitor;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+public class CodeGenUtils {
+ private static final int FLAGS = ClassReader.SKIP_DEBUG;
+
+ public static String disassemble(byte [] bytesCode) {
+ StringWriter strWriter = new StringWriter();
+ PrintWriter writer = new PrintWriter(strWriter);
+
+ ClassReader cr;
+ cr = new ClassReader(bytesCode);
+ cr.accept(new TraceClassVisitor(null, new ASMifier(), writer), FLAGS);
+
+ return strWriter.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CompilationError.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CompilationError.java b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CompilationError.java
new file mode 100644
index 0000000..27054de
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/CompilationError.java
@@ -0,0 +1,31 @@
+/**
+ * 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.tajo.engine.codegen;
+
+import org.apache.tajo.engine.eval.EvalNode;
+
+public class CompilationError extends RuntimeException {
+ public CompilationError(String message) {
+ super(message);
+ }
+
+ public CompilationError(EvalNode evalNode, Throwable t, byte [] clazz) {
+ super("Compilation Error: " + evalNode.toString() + "\n\nBYTES CODE DUMP:\n" + CodeGenUtils.disassemble(clazz), t);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-core/src/main/java/org/apache/tajo/engine/codegen/EvalCodeEmitter.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/codegen/EvalCodeEmitter.java b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/EvalCodeEmitter.java
new file mode 100644
index 0000000..d94c907
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/EvalCodeEmitter.java
@@ -0,0 +1,27 @@
+/*
+ * 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.tajo.engine.codegen;
+
+import org.apache.tajo.engine.eval.EvalNode;
+
+import java.util.Stack;
+
+public interface EvalCodeEmitter<T extends EvalNode> {
+ void emit(EvalCodeGenerator gen, EvalCodeGenContext context, T caseWhen, Stack<EvalNode> stack);
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/7603a3d4/tajo-core/src/main/java/org/apache/tajo/engine/codegen/EvalCodeGenContext.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/codegen/EvalCodeGenContext.java b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/EvalCodeGenContext.java
new file mode 100644
index 0000000..03c0402
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/codegen/EvalCodeGenContext.java
@@ -0,0 +1,223 @@
+/*
+ * 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.tajo.engine.codegen;
+
+import com.google.common.collect.Maps;
+import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.IntervalDatum;
+import org.apache.tajo.engine.eval.*;
+import org.apache.tajo.org.objectweb.asm.ClassWriter;
+import org.apache.tajo.org.objectweb.asm.MethodVisitor;
+import org.apache.tajo.org.objectweb.asm.Opcodes;
+import org.apache.tajo.org.objectweb.asm.commons.GeneratorAdapter;
+import org.apache.tajo.storage.Tuple;
+
+import java.util.Map;
+import java.util.Stack;
+
+public class EvalCodeGenContext extends TajoGeneratorAdapter {
+ final String owner;
+ final Schema schema;
+ final ClassWriter classWriter;
+ final EvalNode evalNode;
+ final Map<EvalNode, String> symbols;
+ int seqId = 0;
+
+ public EvalCodeGenContext(String className, Schema schema, ClassWriter classWriter, EvalNode evalNode) {
+ this.owner = className;
+ this.classWriter = classWriter;
+ this.schema = schema;
+ this.evalNode = evalNode;
+ this.symbols = Maps.newHashMap();
+
+ emitClassDefinition();
+ emitMemberFields();
+ classWriter.visitEnd();
+ emitConstructor();
+
+ String methodName = "eval";
+ String methodDesc = TajoGeneratorAdapter.getMethodDescription(Datum.class, new Class[]{Schema.class, Tuple.class});
+ MethodVisitor evalMethod = classWriter.visitMethod(Opcodes.ACC_PUBLIC, methodName, methodDesc, null, null);
+ evalMethod.visitCode();
+ this.methodvisitor = evalMethod;
+ generatorAdapter = new GeneratorAdapter(this.methodvisitor, access, methodDesc, methodDesc);
+ }
+
+ public void emitClassDefinition() {
+ classWriter.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, this.owner, null,
+ TajoGeneratorAdapter.getInternalName(EvalNode.class), null);
+ }
+
+ public void emitMemberFields() {
+ classWriter.visitField(Opcodes.ACC_PRIVATE, "schema",
+ "L" + TajoGeneratorAdapter.getInternalName(Schema.class) + ";", null, null);
+
+ VariablesPreBuilder builder = new VariablesPreBuilder();
+ builder.visit(this, evalNode, new Stack<EvalNode>());
+ }
+
+ public static void emitCreateSchema(TajoGeneratorAdapter adapter, MethodVisitor mv, Schema schema) {
+ mv.visitLdcInsn(schema.toJson());
+ adapter.invokeStatic(EvalCodeGenerator.class, "createSchema", Schema.class, new Class[] {String.class});
+ }
+
+ public static void emitCreateEval(TajoGeneratorAdapter adapter, MethodVisitor mv, EvalNode evalNode) {
+ mv.visitLdcInsn(evalNode.toJson());
+ adapter.invokeStatic(EvalCodeGenerator.class, "createEval", EvalNode.class, new Class[] {String.class});
+ }
+
+ public static void emitConstEval(TajoGeneratorAdapter adapter, MethodVisitor mv, ConstEval evalNode) {
+ mv.visitLdcInsn(evalNode.toJson());
+ adapter.invokeStatic(EvalCodeGenerator.class, "createConstEval", ConstEval.class, new Class[] {String.class});
+ }
+
+ public static void emitRowConstantEval(TajoGeneratorAdapter adapter, MethodVisitor mv, RowConstantEval evalNode) {
+ mv.visitLdcInsn(evalNode.toJson());
+ adapter.invokeStatic(EvalCodeGenerator.class, "createRowConstantEval", RowConstantEval.class,
+ new Class[] {String.class});
+ }
+
+ public void emitConstructor() {
+ // constructor method
+ MethodVisitor initMethod = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
+ initMethod.visitCode();
+ initMethod.visitVarInsn(Opcodes.ALOAD, 0);
+ initMethod.visitMethodInsn(Opcodes.INVOKESPECIAL, TajoGeneratorAdapter.getInternalName(EvalNode.class), "<init>",
+ "()V");
+
+ TajoGeneratorAdapter consAdapter = new TajoGeneratorAdapter(Opcodes.ACC_PUBLIC, initMethod, "<init>", "()V");
+
+ // == this.schema = schema;
+ if (schema != null) {
+ consAdapter.aload(0);
+ emitCreateSchema(consAdapter, initMethod, schema);
+ initMethod.visitFieldInsn(Opcodes.PUTFIELD, this.owner, "schema", getDescription(Schema.class));
+ }
+
+ for (Map.Entry<EvalNode, String> entry : symbols.entrySet()) {
+ if (entry.getKey().getType() == EvalType.CONST) {
+ ConstEval constEval = (ConstEval) entry.getKey();
+
+ if (constEval.getValueType().getType() == TajoDataTypes.Type.INTERVAL) {
+ IntervalDatum datum = (IntervalDatum) constEval.getValue();
+
+ final String internalName = TajoGeneratorAdapter.getInternalName(IntervalDatum.class);
+
+ initMethod.visitTypeInsn(Opcodes.NEW, internalName);
+ consAdapter.dup();
+ initMethod.visitLdcInsn(datum.getMonths());
+ initMethod.visitLdcInsn(datum.getMilliSeconds());
+ initMethod.visitMethodInsn(Opcodes.INVOKESPECIAL, internalName, "<init>", "(IJ)V");
+ int INTERVAL_DATUM = consAdapter.astore();
+
+ consAdapter.aload(0);
+ consAdapter.aload(INTERVAL_DATUM);
+ initMethod.visitFieldInsn(Opcodes.PUTFIELD, this.owner, entry.getValue(),
+ "L" + TajoGeneratorAdapter.getInternalName(IntervalDatum.class) + ";");
+ }
+
+ } else if (entry.getKey().getType() == EvalType.IN) {
+ InEval inEval = (InEval) entry.getKey();
+
+ final String internalName = getInternalName(InEval.class);
+ initMethod.visitTypeInsn(Opcodes.NEW, internalName);
+ consAdapter.dup();
+ emitCreateEval(consAdapter, initMethod, inEval.getLeftExpr());
+ emitRowConstantEval(consAdapter, initMethod, (RowConstantEval) inEval.getRightExpr());
+ consAdapter.push(inEval.isNot());
+ consAdapter.invokeSpecial(InEval.class, "<init>", void.class,
+ new Class [] {EvalNode.class, RowConstantEval.class, boolean.class});
+ int IN_PREDICATE_EVAL = consAdapter.astore();
+
+ consAdapter.aload(0);
+ consAdapter.aload(IN_PREDICATE_EVAL);
+ initMethod.visitFieldInsn(Opcodes.PUTFIELD, this.owner, entry.getValue(), getDescription(InEval.class));
+
+ } else if (EvalType.isStringPatternMatchOperator(entry.getKey().getType())) {
+ PatternMatchPredicateEval patternPredicate = (PatternMatchPredicateEval) entry.getKey();
+
+ Class clazz = EvalCodeGenerator.getStringPatternEvalClass(entry.getKey().getType());
+ final String internalName = TajoGeneratorAdapter.getInternalName(clazz);
+
+ initMethod.visitTypeInsn(Opcodes.NEW, internalName);
+ consAdapter.dup();
+ consAdapter.push(patternPredicate.isNot());
+ emitCreateEval(consAdapter, initMethod, patternPredicate.getLeftExpr());
+ emitConstEval(consAdapter, initMethod, (ConstEval) patternPredicate.getRightExpr());
+ consAdapter.push(patternPredicate.isCaseInsensitive());
+ consAdapter.invokeSpecial(clazz, "<init>", void.class,
+ new Class [] {boolean.class, EvalNode.class, ConstEval.class, boolean.class});
+
+ int PatternEval = consAdapter.astore();
+
+ consAdapter.aload(0);
+ consAdapter.aload(PatternEval);
+ initMethod.visitFieldInsn(Opcodes.PUTFIELD, this.owner, entry.getValue(), getDescription(clazz));
+
+ } else if (entry.getKey().getType() == EvalType.FUNCTION) {
+ GeneralFunctionEval function = (GeneralFunctionEval) entry.getKey();
+ final String internalName = TajoGeneratorAdapter.getInternalName(function.getFuncDesc().getFuncClass());
+
+ // new and initialization of function
+ initMethod.visitTypeInsn(Opcodes.NEW, internalName);
+ consAdapter.dup();
+ initMethod.visitMethodInsn(Opcodes.INVOKESPECIAL, internalName, "<init>", "()V");
+ int FUNCTION = consAdapter.astore();
+
+ // commParam
+ int paramNum = function.getArgs().length;
+ initMethod.visitLdcInsn(paramNum);
+ consAdapter.newArray(FunctionEval.ParamType.class);
+ final int PARAM_TYPE_ARRAY = consAdapter.astore();
+ FunctionEval.ParamType[] paramTypes = EvalCodeGenerator.getParamTypes(function.getArgs());
+ for (int paramIdx = 0; paramIdx < paramTypes.length; paramIdx++) {
+ consAdapter.aload(PARAM_TYPE_ARRAY);
+ consAdapter.methodvisitor.visitLdcInsn(paramIdx);
+ consAdapter.methodvisitor.visitFieldInsn(Opcodes.GETSTATIC, TajoGeneratorAdapter.getInternalName(FunctionEval.ParamType.class),
+ paramTypes[paramIdx].name(), TajoGeneratorAdapter.getDescription(FunctionEval.ParamType.class));
+ consAdapter.methodvisitor.visitInsn(Opcodes.AASTORE);
+ }
+
+ initMethod.visitVarInsn(Opcodes.ALOAD, FUNCTION);
+ consAdapter.aload(PARAM_TYPE_ARRAY);
+ consAdapter.invokeVirtual(function.getFuncDesc().getFuncClass(), "init", void.class, new Class[] {FunctionEval.ParamType[].class});
+
+ initMethod.visitVarInsn(Opcodes.ALOAD, 0);
+ initMethod.visitVarInsn(Opcodes.ALOAD, FUNCTION);
+ initMethod.visitFieldInsn(Opcodes.PUTFIELD, this.owner, entry.getValue(),
+ "L" + TajoGeneratorAdapter.getInternalName(function.getFuncDesc().getFuncClass()) + ";");
+
+ }
+ }
+
+ initMethod.visitInsn(Opcodes.RETURN);
+ initMethod.visitMaxs(1, 1);
+ initMethod.visitEnd();
+ }
+
+ public void emitReturn() {
+ convertToDatum(evalNode.getValueType(), true);
+ methodvisitor.visitInsn(Opcodes.ARETURN);
+ methodvisitor.visitMaxs(0, 0);
+ methodvisitor.visitEnd();
+ classWriter.visitEnd();
+ }
+}
|