Fix compilation errors from sync with master
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/a9526a94 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/a9526a94 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/a9526a94 Branch: refs/heads/calcite Commit: a9526a94bd603aceeb5c83d4371830815c57e2ad Parents: 9a08a9d 1ce9845 Author: maryannxue <maryann....@gmail.com> Authored: Wed Sep 14 10:31:57 2016 -0700 Committer: maryannxue <maryann....@gmail.com> Committed: Wed Sep 14 10:31:57 2016 -0700 ---------------------------------------------------------------------- .gitignore | 1 + KEYS | 58 + LICENSE | 174 + NOTICE | 29 +- README.md | 17 + bin/hadoop-metrics2-hbase.properties | 16 + bin/hadoop-metrics2-phoenix.properties | 19 +- bin/hbase-site.xml | 2 - bin/log4j.properties | 2 +- bin/phoenix_utils.py | 12 +- bin/queryserver.py | 38 +- bin/sqlline-thin.py | 4 +- bin/sqlline.py | 39 +- bin/tephra | 6 +- build.txt | 2 - dev/make_rc.sh | 12 +- dev/release_files/LICENSE | 1615 ++- dev/release_files/NOTICE | 320 +- dev/test-patch.properties | 1 + dev/test-patch.sh | 32 + examples/STOCK_SYMBOL.sql | 1 - examples/WEB_STAT_QUERIES.sql | 1 - examples/pig/test.pig | 17 + phoenix-assembly/pom.xml | 91 +- phoenix-assembly/src/build/client-minimal.xml | 38 - phoenix-assembly/src/build/client-spark.xml | 74 - .../src/build/client-without-hbase.xml | 40 - phoenix-assembly/src/build/client.xml | 98 - .../src/build/components-major-client.xml | 57 - .../src/build/components-minimal.xml | 77 - .../components/all-common-dependencies.xml | 2 +- .../src/build/components/all-common-jars.xml | 42 +- phoenix-assembly/src/build/server.xml | 53 - phoenix-client/pom.xml | 378 + phoenix-core/pom.xml | 45 +- ...ReplayWithIndexWritesAndCompressedWALIT.java | 18 +- .../phoenix/end2end/AbsFunctionEnd2EndIT.java | 11 +- .../phoenix/end2end/AggregateQueryIT.java | 20 +- .../AlterMultiTenantTableWithViewsIT.java | 704 ++ .../apache/phoenix/end2end/AlterSessionIT.java | 20 +- .../apache/phoenix/end2end/AlterTableIT.java | 29 +- .../phoenix/end2end/AlterTableWithViewsIT.java | 1013 +- .../phoenix/end2end/AppendOnlySchemaIT.java | 356 + .../phoenix/end2end/ArithmeticQueryIT.java | 314 +- .../phoenix/end2end/ArrayAppendFunctionIT.java | 186 +- .../phoenix/end2end/ArrayConcatFunctionIT.java | 160 +- .../phoenix/end2end/ArrayFillFunctionIT.java | 175 +- .../org/apache/phoenix/end2end/ArrayIT.java | 55 +- .../phoenix/end2end/ArrayPrependFunctionIT.java | 220 +- .../end2end/ArrayToStringFunctionIT.java | 326 +- .../phoenix/end2end/ArraysWithNullsIT.java | 152 +- .../apache/phoenix/end2end/AutoCommitIT.java | 21 +- .../phoenix/end2end/AutoPartitionViewsIT.java | 392 + .../end2end/BaseClientManagedTimeIT.java | 2 +- .../phoenix/end2end/BaseHBaseManagedTimeIT.java | 7 +- .../BaseHBaseManagedTimeTableReuseIT.java | 73 + .../BaseOwnClusterClientManagedTimeIT.java | 6 +- .../BaseOwnClusterHBaseManagedTimeIT.java | 6 +- .../phoenix/end2end/BaseOwnClusterIT.java | 4 +- .../org/apache/phoenix/end2end/BaseQueryIT.java | 6 +- .../end2end/BaseTenantSpecificViewIndexIT.java | 80 +- .../org/apache/phoenix/end2end/BaseViewIT.java | 15 +- .../apache/phoenix/end2end/BinaryRowKeyIT.java | 33 +- .../phoenix/end2end/CSVCommonsLoaderIT.java | 80 +- .../apache/phoenix/end2end/CaseStatementIT.java | 4 +- .../apache/phoenix/end2end/CastAndCoerceIT.java | 4 +- .../phoenix/end2end/CbrtFunctionEnd2EndIT.java | 35 +- .../phoenix/end2end/ClientManagedTimeTest.java | 4 +- .../end2end/ClientTimeArithmeticQueryIT.java | 4 +- .../phoenix/end2end/CoalesceFunctionIT.java | 117 +- .../end2end/ColumnProjectionOptimizationIT.java | 17 +- .../end2end/ConvertTimezoneFunctionIT.java | 85 +- .../end2end/CountDistinctCompressionIT.java | 3 +- .../apache/phoenix/end2end/CreateSchemaIT.java | 83 + .../apache/phoenix/end2end/CreateTableIT.java | 81 +- .../phoenix/end2end/CsvBulkLoadToolIT.java | 4 + .../phoenix/end2end/CustomEntityDataIT.java | 2 +- .../org/apache/phoenix/end2end/DateTimeIT.java | 209 +- .../phoenix/end2end/DecodeFunctionIT.java | 49 +- .../org/apache/phoenix/end2end/DeleteIT.java | 176 +- .../apache/phoenix/end2end/DerivedTableIT.java | 3 +- .../phoenix/end2end/DisableLocalIndexIT.java | 18 +- .../apache/phoenix/end2end/DistinctCountIT.java | 80 +- .../phoenix/end2end/DistinctPrefixFilterIT.java | 395 + .../apache/phoenix/end2end/DropSchemaIT.java | 138 + .../apache/phoenix/end2end/DynamicColumnIT.java | 119 +- .../apache/phoenix/end2end/DynamicFamilyIT.java | 31 +- .../apache/phoenix/end2end/DynamicUpsertIT.java | 11 +- .../phoenix/end2end/EncodeFunctionIT.java | 42 +- .../phoenix/end2end/End2EndTestDriver.java | 2 - .../phoenix/end2end/EvaluationOfORIT.java | 13 +- .../phoenix/end2end/ExecuteStatementsIT.java | 42 +- .../phoenix/end2end/ExpFunctionEnd2EndIT.java | 20 +- .../phoenix/end2end/ExtendedQueryExecIT.java | 12 +- .../phoenix/end2end/FirstValueFunctionIT.java | 144 +- .../apache/phoenix/end2end/FunkyNamesIT.java | 2 +- .../end2end/GetSetByteBitFunctionEnd2EndIT.java | 26 +- .../apache/phoenix/end2end/GroupByCaseIT.java | 245 +- .../org/apache/phoenix/end2end/GroupByIT.java | 4 +- .../end2end/HBaseManagedTimeTableReuseTest.java | 47 + .../phoenix/end2end/HBaseManagedTimeTest.java | 8 +- .../org/apache/phoenix/end2end/HashJoinIT.java | 55 +- .../phoenix/end2end/HashJoinLocalIndexIT.java | 13 +- .../apache/phoenix/end2end/HashJoinMoreIT.java | 301 +- .../org/apache/phoenix/end2end/InListIT.java | 41 +- .../phoenix/end2end/InMemoryOrderByIT.java | 6 +- .../org/apache/phoenix/end2end/IndexToolIT.java | 21 +- .../apache/phoenix/end2end/InstrFunctionIT.java | 48 +- .../org/apache/phoenix/end2end/IsNullIT.java | 37 +- .../org/apache/phoenix/end2end/KeyOnlyIT.java | 6 +- .../phoenix/end2end/LastValueFunctionIT.java | 194 +- .../phoenix/end2end/LikeExpressionIT.java | 77 +- .../phoenix/end2end/LnLogFunctionEnd2EndIT.java | 15 +- .../apache/phoenix/end2end/MD5FunctionIT.java | 30 +- .../org/apache/phoenix/end2end/MapReduceIT.java | 61 +- .../phoenix/end2end/MappingTableDataTypeIT.java | 17 +- .../end2end/MinMaxAggregateFunctionIT.java | 24 +- .../phoenix/end2end/ModulusExpressionIT.java | 45 +- .../phoenix/end2end/MultiCfQueryExecIT.java | 2 +- .../end2end/NamespaceSchemaMappingIT.java | 115 + .../phoenix/end2end/NativeHBaseTypesIT.java | 2 +- .../end2end/NeedsOwnMiniClusterTest.java | 4 +- .../org/apache/phoenix/end2end/NotQueryIT.java | 4 +- .../phoenix/end2end/NthValueFunctionIT.java | 252 +- .../end2end/OctetLengthFunctionEnd2EndIT.java | 13 +- .../org/apache/phoenix/end2end/OrderByIT.java | 98 +- .../phoenix/end2end/ParallelIteratorsIT.java | 6 +- .../apache/phoenix/end2end/PercentileIT.java | 137 +- .../phoenix/end2end/PhoenixRuntimeIT.java | 44 +- .../phoenix/end2end/PowerFunctionEnd2EndIT.java | 21 +- .../apache/phoenix/end2end/PrimitiveTypeIT.java | 63 +- .../phoenix/end2end/ProductMetricsIT.java | 2 +- .../end2end/QueryDatabaseMetaDataIT.java | 162 +- .../phoenix/end2end/QueryExecWithoutSCNIT.java | 6 +- .../org/apache/phoenix/end2end/QueryMoreIT.java | 31 +- .../apache/phoenix/end2end/QueryTimeoutIT.java | 36 +- .../phoenix/end2end/QueryWithLimitIT.java | 8 +- .../phoenix/end2end/QueryWithOffsetIT.java | 62 +- .../apache/phoenix/end2end/RTrimFunctionIT.java | 24 +- .../phoenix/end2end/ReadIsolationLevelIT.java | 2 +- .../org/apache/phoenix/end2end/ReadOnlyIT.java | 17 +- .../end2end/RegexpReplaceFunctionIT.java | 17 +- .../phoenix/end2end/RegexpSplitFunctionIT.java | 69 +- .../phoenix/end2end/RegexpSubstrFunctionIT.java | 12 +- .../apache/phoenix/end2end/RenewLeaseIT.java | 90 + .../phoenix/end2end/ReverseFunctionIT.java | 42 +- .../apache/phoenix/end2end/ReverseScanIT.java | 58 +- .../RoundFloorCeilFunctionsEnd2EndIT.java | 101 +- .../phoenix/end2end/RowValueConstructorIT.java | 83 +- .../org/apache/phoenix/end2end/ScanQueryIT.java | 4 +- .../org/apache/phoenix/end2end/SequenceIT.java | 58 +- .../phoenix/end2end/SerialIteratorsIT.java | 90 + .../phoenix/end2end/ServerExceptionIT.java | 9 +- .../org/apache/phoenix/end2end/Shadower.java | 4 +- .../phoenix/end2end/SignFunctionEnd2EndIT.java | 35 +- .../end2end/SkipScanAfterManualSplitIT.java | 44 +- .../apache/phoenix/end2end/SkipScanQueryIT.java | 156 +- .../apache/phoenix/end2end/SortMergeJoinIT.java | 11 +- .../phoenix/end2end/SortMergeJoinMoreIT.java | 257 +- .../org/apache/phoenix/end2end/SortOrderIT.java | 303 +- .../phoenix/end2end/SpillableGroupByIT.java | 2 +- .../phoenix/end2end/SpooledOrderByIT.java | 4 +- .../phoenix/end2end/SpooledTmpFileDeleteIT.java | 20 +- .../phoenix/end2end/SqrtFunctionEnd2EndIT.java | 25 +- .../phoenix/end2end/StatementHintsIT.java | 12 +- .../org/apache/phoenix/end2end/StddevIT.java | 18 +- .../apache/phoenix/end2end/StoreNullsIT.java | 51 +- .../org/apache/phoenix/end2end/StringIT.java | 66 +- .../end2end/StringToArrayFunctionIT.java | 164 +- .../org/apache/phoenix/end2end/SubqueryIT.java | 24 +- .../end2end/SubqueryUsingSortMergeJoinIT.java | 12 +- .../apache/phoenix/end2end/TenantIdTypeIT.java | 4 +- .../end2end/TenantSpecificTablesDDLIT.java | 5 +- .../end2end/TenantSpecificViewIndexIT.java | 219 +- .../end2end/TimezoneOffsetFunctionIT.java | 63 +- .../phoenix/end2end/ToCharFunctionIT.java | 54 +- .../phoenix/end2end/ToDateFunctionIT.java | 9 +- .../java/org/apache/phoenix/end2end/TopNIT.java | 8 +- .../phoenix/end2end/TruncateFunctionIT.java | 2 +- .../org/apache/phoenix/end2end/UnionAllIT.java | 325 +- .../apache/phoenix/end2end/UnnestArrayIT.java | 18 +- .../org/apache/phoenix/end2end/UpgradeIT.java | 320 +- .../phoenix/end2end/UpsertBigValuesIT.java | 78 +- .../end2end/UpsertSelectAutoCommitIT.java | 50 +- .../apache/phoenix/end2end/UpsertSelectIT.java | 20 +- .../apache/phoenix/end2end/UpsertValuesIT.java | 44 +- .../org/apache/phoenix/end2end/UseSchemaIT.java | 146 + .../phoenix/end2end/UserDefinedFunctionsIT.java | 60 +- .../phoenix/end2end/VariableLengthPKIT.java | 38 +- .../java/org/apache/phoenix/end2end/ViewIT.java | 35 +- .../end2end/index/AsyncImmutableIndexIT.java | 114 + .../end2end/index/AsyncIndexDisabledIT.java | 78 + .../phoenix/end2end/index/DropMetadataIT.java | 303 + .../phoenix/end2end/index/DropViewIT.java | 105 - .../index/GlobalIndexOptimizationIT.java | 175 +- .../phoenix/end2end/index/ImmutableIndexIT.java | 36 +- .../end2end/index/IndexExpressionIT.java | 431 +- .../apache/phoenix/end2end/index/IndexIT.java | 144 +- .../phoenix/end2end/index/IndexMetadataIT.java | 293 +- .../phoenix/end2end/index/LocalIndexIT.java | 724 +- .../end2end/index/MutableIndexFailureIT.java | 60 +- .../phoenix/end2end/index/MutableIndexIT.java | 331 +- .../end2end/index/ReadOnlyIndexFailureIT.java | 10 + .../phoenix/end2end/index/SaltedIndexIT.java | 95 +- .../phoenix/end2end/index/ViewIndexIT.java | 137 +- .../end2end/index/txn/MutableRollbackIT.java | 82 +- .../phoenix/end2end/index/txn/RollbackIT.java | 20 +- .../end2end/index/txn/TxWriteFailureIT.java | 2 +- .../phoenix/end2end/salted/SaltedTableIT.java | 2 +- .../salted/SaltedTableUpsertSelectIT.java | 87 +- .../salted/SaltedTableVarLengthRowKeyIT.java | 12 +- .../apache/phoenix/execute/PartialCommitIT.java | 4 +- .../index/balancer/IndexLoadBalancerIT.java | 485 - .../DelayedTableResultIteratorFactory.java | 9 +- .../iterate/MockParallelIteratorFactory.java | 3 +- .../phoenix/iterate/PhoenixQueryTimeoutIT.java | 26 +- .../iterate/RoundRobinResultIteratorIT.java | 26 +- .../apache/phoenix/rpc/PhoenixServerRpcIT.java | 21 - .../org/apache/phoenix/rpc/UpdateCacheIT.java | 26 +- .../phoenix/rpc/UpdateCacheWithScnIT.java | 2 +- .../apache/phoenix/trace/BaseTracingTestIT.java | 4 +- .../org/apache/phoenix/tx/TransactionIT.java | 315 +- .../org/apache/phoenix/tx/TxCheckpointIT.java | 63 +- phoenix-core/src/main/antlr3/PhoenixSQL.g | 22 + .../hadoop/hbase/ipc/PhoenixRpcScheduler.java | 8 +- .../ipc/controller/MetadataRpcController.java | 12 +- .../regionserver/IndexHalfStoreFileReader.java | 412 +- .../IndexHalfStoreFileReaderGenerator.java | 172 +- .../regionserver/IndexSplitTransaction.java | 986 -- .../hbase/regionserver/LocalIndexMerger.java | 123 - .../hbase/regionserver/LocalIndexSplitter.java | 174 - .../LocalIndexStoreFileScanner.java | 268 + .../org/apache/phoenix/cache/GlobalCache.java | 4 +- .../phoenix/cache/IndexMetaDataCache.java | 2 +- .../apache/phoenix/cache/JodaTimezoneCache.java | 16 +- .../apache/phoenix/cache/ServerCacheClient.java | 48 +- .../cache/aggcache/SpillableGroupByCache.java | 5 +- .../apache/phoenix/calcite/PhoenixSchema.java | 3 +- .../apache/phoenix/calcite/TableMapping.java | 5 +- .../calcite/rel/PhoenixRelImplementorImpl.java | 2 +- .../phoenix/calcite/rel/PhoenixTableModify.java | 2 +- .../rel/PhoenixToEnumerableConverter.java | 5 + .../phoenix/compile/AggregationManager.java | 60 + .../apache/phoenix/compile/ColumnResolver.java | 10 + .../phoenix/compile/CreateSchemaCompiler.java | 65 + .../phoenix/compile/CreateTableCompiler.java | 18 +- .../apache/phoenix/compile/DeleteCompiler.java | 93 +- .../phoenix/compile/ExpressionCompiler.java | 6 +- .../apache/phoenix/compile/FromCompiler.java | 177 +- .../apache/phoenix/compile/GroupByCompiler.java | 100 +- .../phoenix/compile/IndexStatementRewriter.java | 12 +- .../apache/phoenix/compile/JoinCompiler.java | 38 +- .../phoenix/compile/ListJarsQueryPlan.java | 4 + .../MutatingParallelIteratorFactory.java | 2 +- .../apache/phoenix/compile/OrderByCompiler.java | 18 +- .../phoenix/compile/OrderPreservingTracker.java | 9 + .../apache/phoenix/compile/PostDDLCompiler.java | 25 +- .../compile/PostLocalIndexDDLCompiler.java | 23 +- .../phoenix/compile/ProjectionCompiler.java | 63 +- .../apache/phoenix/compile/QueryCompiler.java | 18 +- .../org/apache/phoenix/compile/QueryPlan.java | 2 + .../org/apache/phoenix/compile/ScanRanges.java | 104 +- .../phoenix/compile/StatementContext.java | 5 +- .../apache/phoenix/compile/TraceQueryPlan.java | 5 + .../compile/TupleProjectionCompiler.java | 16 +- .../apache/phoenix/compile/UnionCompiler.java | 161 +- .../apache/phoenix/compile/UpsertCompiler.java | 103 +- .../apache/phoenix/compile/WhereOptimizer.java | 64 +- .../coprocessor/BaseScannerRegionObserver.java | 217 +- .../coprocessor/DelegateRegionObserver.java | 248 +- .../coprocessor/DelegateRegionScanner.java | 2 +- .../phoenix/coprocessor/GroupByCache.java | 5 +- .../GroupedAggregateRegionObserver.java | 34 +- .../coprocessor/HashJoinRegionScanner.java | 5 +- .../coprocessor/MetaDataEndpointImpl.java | 956 +- .../phoenix/coprocessor/MetaDataProtocol.java | 169 +- .../coprocessor/MetaDataRegionObserver.java | 25 +- .../PhoenixTransactionalProcessor.java | 2 +- .../phoenix/coprocessor/ScanRegionObserver.java | 20 +- .../coprocessor/SequenceRegionObserver.java | 7 + .../UngroupedAggregateRegionObserver.java | 255 +- .../coprocessor/generated/MetaDataProtos.java | 9554 +++++++++++++----- .../coprocessor/generated/PSchemaProtos.java | 666 ++ .../coprocessor/generated/PTableProtos.java | 361 +- .../phoenix/exception/SQLExceptionCode.java | 38 +- .../exception/UndecodableByteException.java | 4 +- .../apache/phoenix/execute/AggregatePlan.java | 42 +- .../apache/phoenix/execute/BaseQueryPlan.java | 30 +- .../phoenix/execute/ClientAggregatePlan.java | 6 + .../apache/phoenix/execute/ClientScanPlan.java | 7 +- .../apache/phoenix/execute/CorrelatePlan.java | 8 +- .../phoenix/execute/DegenerateQueryPlan.java | 2 +- .../apache/phoenix/execute/HashJoinPlan.java | 8 +- .../execute/LiteralResultIterationPlan.java | 2 +- .../apache/phoenix/execute/MutationState.java | 382 +- .../org/apache/phoenix/execute/ScanPlan.java | 121 +- .../phoenix/execute/SortMergeJoinPlan.java | 8 +- .../phoenix/execute/TupleProjectionPlan.java | 8 +- .../org/apache/phoenix/execute/UnionPlan.java | 6 +- .../apache/phoenix/execute/UnnestArrayPlan.java | 8 +- .../expression/ByteBasedLikeExpression.java | 4 +- .../phoenix/expression/InListExpression.java | 4 +- .../expression/RowKeyColumnExpression.java | 6 +- .../RowValueConstructorExpression.java | 30 +- .../expression/StringBasedLikeExpression.java | 3 +- .../DistinctValueWithCountServerAggregator.java | 11 +- .../function/ArrayLengthFunction.java | 2 +- .../ByteBasedRegexpReplaceFunction.java | 3 +- .../function/ByteBasedRegexpSplitFunction.java | 3 +- .../function/ByteBasedRegexpSubstrFunction.java | 3 +- .../expression/function/CeilDateExpression.java | 2 +- .../function/CeilDecimalExpression.java | 12 +- .../function/CeilTimestampExpression.java | 14 +- .../expression/function/CoalesceFunction.java | 6 +- .../function/ConvertTimezoneFunction.java | 14 +- .../DistinctCountAggregateFunction.java | 6 +- .../expression/function/EncodeFormat.java | 14 +- .../function/FloorDateExpression.java | 2 +- .../function/FloorDecimalExpression.java | 12 +- .../function/RoundDateExpression.java | 2 +- .../function/RoundDecimalExpression.java | 2 +- .../function/RoundTimestampExpression.java | 2 +- .../StringBasedRegexpReplaceFunction.java | 3 +- .../StringBasedRegexpSubstrFunction.java | 3 +- .../expression/function/ToCharFunction.java | 3 + .../phoenix/filter/BooleanExpressionFilter.java | 1 + .../phoenix/filter/DistinctPrefixFilter.java | 154 + .../filter/MultiKeyValueComparisonFilter.java | 1 - .../hbase/index/IndexRegionSplitPolicy.java | 52 +- .../org/apache/phoenix/hbase/index/Indexer.java | 84 +- .../hbase/index/balancer/IndexLoadBalancer.java | 671 +- .../hbase/index/covered/IndexMetaData.java | 9 +- .../hbase/index/covered/NonTxIndexBuilder.java | 6 +- .../index/covered/update/ColumnReference.java | 9 +- .../hbase/index/master/IndexMasterObserver.java | 88 - .../index/util/ReadOnlyImmutableBytesPtr.java | 59 - .../hbase/index/write/IndexCommitter.java | 2 +- .../phoenix/hbase/index/write/IndexWriter.java | 37 +- .../write/ParallelWriterIndexCommitter.java | 42 +- .../hbase/index/write/RecoveryIndexWriter.java | 134 + .../TrackingParallelWriterIndexCommitter.java | 47 +- .../apache/phoenix/index/IndexMaintainer.java | 74 +- .../index/IndexMetaDataCacheFactory.java | 2 +- .../phoenix/index/PhoenixIndexBuilder.java | 64 - .../apache/phoenix/index/PhoenixIndexCodec.java | 6 +- .../index/PhoenixIndexFailurePolicy.java | 13 +- .../phoenix/index/PhoenixIndexMetaData.java | 17 +- .../index/PhoenixTransactionalIndexer.java | 111 +- .../iterate/AggregatingResultIterator.java | 4 +- .../BaseGroupedAggregatingResultIterator.java | 3 +- .../phoenix/iterate/BaseResultIterators.java | 181 +- .../phoenix/iterate/ChunkedResultIterator.java | 69 +- .../DefaultTableResultIteratorFactory.java | 5 +- .../DistinctAggregatingResultIterator.java | 15 +- .../apache/phoenix/iterate/ExplainTable.java | 26 +- .../FilterAggregatingResultIterator.java | 8 +- .../phoenix/iterate/OffsetResultIterator.java | 2 +- .../OrderedAggregatingResultIterator.java | 5 +- .../iterate/ParallelIteratorFactory.java | 5 +- .../phoenix/iterate/ParallelIterators.java | 42 +- .../RowKeyOrderedAggregateResultIterator.java | 190 + .../apache/phoenix/iterate/SerialIterators.java | 156 +- .../phoenix/iterate/SpoolingResultIterator.java | 20 +- .../phoenix/iterate/TableResultIterator.java | 81 +- .../iterate/TableResultIteratorFactory.java | 3 +- .../apache/phoenix/jdbc/PhoenixConnection.java | 105 +- .../phoenix/jdbc/PhoenixDatabaseMetaData.java | 180 +- .../org/apache/phoenix/jdbc/PhoenixDriver.java | 41 +- .../phoenix/jdbc/PhoenixEmbeddedDriver.java | 136 +- .../apache/phoenix/jdbc/PhoenixStatement.java | 93 +- .../phoenix/mapreduce/AbstractBulkLoadTool.java | 80 +- .../phoenix/mapreduce/CsvBulkImportUtil.java | 7 + .../mapreduce/FormatToBytesWritableMapper.java | 122 +- .../mapreduce/FormatToKeyValueReducer.java | 71 +- .../mapreduce/MultiHfileOutputFormat.java | 4 +- .../phoenix/mapreduce/PhoenixInputFormat.java | 2 - .../phoenix/mapreduce/PhoenixRecordReader.java | 5 +- .../phoenix/mapreduce/index/IndexTool.java | 74 +- .../phoenix/mapreduce/index/IndexToolUtil.java | 4 +- .../index/PhoenixIndexImportDirectReducer.java | 60 + .../index/PhoenixIndexImportMapper.java | 7 +- .../index/PhoenixIndexToolReducer.java | 60 - .../index/automation/PhoenixAsyncIndex.java | 75 + .../index/automation/PhoenixMRJobCallable.java | 73 + .../index/automation/PhoenixMRJobSubmitter.java | 290 + .../index/automation/YarnApplication.java | 208 + .../phoenix/memory/GlobalMemoryManager.java | 30 +- .../apache/phoenix/optimize/QueryOptimizer.java | 23 +- .../org/apache/phoenix/parse/ColumnDef.java | 7 +- .../phoenix/parse/CreateSchemaStatement.java | 42 + .../phoenix/parse/DropSchemaStatement.java | 55 + .../parse/IndexExpressionParseNodeRewriter.java | 8 +- .../java/org/apache/phoenix/parse/PSchema.java | 86 + .../apache/phoenix/parse/ParseNodeFactory.java | 12 + .../phoenix/parse/UseSchemaStatement.java | 36 + .../apache/phoenix/protobuf/ProtobufUtil.java | 18 +- .../phoenix/query/ConnectionQueryServices.java | 22 +- .../query/ConnectionQueryServicesImpl.java | 1179 ++- .../query/ConnectionlessQueryServicesImpl.java | 108 +- .../query/DelegateConnectionQueryServices.java | 79 +- .../apache/phoenix/query/MetaDataMutated.java | 18 +- .../apache/phoenix/query/QueryConstants.java | 26 +- .../org/apache/phoenix/query/QueryServices.java | 19 +- .../phoenix/query/QueryServicesOptions.java | 31 +- .../apache/phoenix/query/TableStatsCache.java | 192 + .../apache/phoenix/schema/DelegateTable.java | 21 +- .../apache/phoenix/schema/MetaDataClient.java | 804 +- .../NewerSchemaAlreadyExistsException.java | 26 + .../org/apache/phoenix/schema/PMetaData.java | 6 +- .../apache/phoenix/schema/PMetaDataCache.java | 221 + .../apache/phoenix/schema/PMetaDataImpl.java | 344 +- .../phoenix/schema/PSynchronizedMetaData.java | 249 + .../java/org/apache/phoenix/schema/PTable.java | 20 +- .../org/apache/phoenix/schema/PTableImpl.java | 227 +- .../org/apache/phoenix/schema/PTableKey.java | 2 + .../org/apache/phoenix/schema/PTableRef.java | 56 +- .../apache/phoenix/schema/PTableRefFactory.java | 52 + .../apache/phoenix/schema/PTableRefImpl.java | 39 + .../schema/SchemaAlreadyExistsException.java | 53 + .../phoenix/schema/SchemaNotFoundException.java | 52 + .../org/apache/phoenix/schema/Sequence.java | 20 +- .../phoenix/schema/SerializedPTableRef.java | 47 + .../schema/SerializedPTableRefFactory.java | 37 + .../org/apache/phoenix/schema/SortOrder.java | 2 - .../apache/phoenix/schema/TableProperty.java | 11 +- .../org/apache/phoenix/schema/TableRef.java | 3 +- .../org/apache/phoenix/schema/ValueSchema.java | 30 +- .../stats/DefaultStatisticsCollector.java | 4 +- .../schema/stats/GuidePostsInfoBuilder.java | 6 +- .../stats/StatisticsCollectionRunTracker.java | 1 - .../schema/stats/StatisticsCollectionScope.java | 6 +- .../stats/StatisticsCollectorFactory.java | 16 +- .../phoenix/schema/stats/StatisticsScanner.java | 18 +- .../phoenix/schema/stats/StatisticsUtil.java | 27 + .../phoenix/schema/stats/StatisticsWriter.java | 20 +- .../phoenix/schema/types/PArrayDataType.java | 4 +- .../org/apache/phoenix/schema/types/PChar.java | 4 + .../apache/phoenix/schema/types/PDataType.java | 12 + .../org/apache/phoenix/schema/types/PDate.java | 2 +- .../apache/phoenix/schema/types/PDecimal.java | 8 + .../apache/phoenix/schema/types/PTimestamp.java | 2 +- .../phoenix/trace/PhoenixMetricsSink.java | 2 +- .../org/apache/phoenix/util/ConfigUtil.java | 2 - .../java/org/apache/phoenix/util/DateUtil.java | 17 +- .../java/org/apache/phoenix/util/IndexUtil.java | 135 +- .../apache/phoenix/util/InstanceResolver.java | 7 + .../java/org/apache/phoenix/util/JDBCUtil.java | 5 + .../org/apache/phoenix/util/MetaDataUtil.java | 244 +- .../apache/phoenix/util/PhoenixMRJobUtil.java | 233 + .../org/apache/phoenix/util/PhoenixRuntime.java | 128 +- .../java/org/apache/phoenix/util/QueryUtil.java | 75 +- .../java/org/apache/phoenix/util/ScanUtil.java | 99 +- .../org/apache/phoenix/util/SchemaUtil.java | 166 +- .../apache/phoenix/util/TransactionUtil.java | 20 +- .../org/apache/phoenix/util/UpgradeUtil.java | 622 +- .../phoenix/util/ZKBasedMasterElectionUtil.java | 70 + .../phoenix/cache/JodaTimezoneCacheTest.java | 16 +- .../compile/CreateTableCompilerTest.java | 47 + .../phoenix/compile/QueryCompilerTest.java | 151 + .../phoenix/compile/QueryOptimizerTest.java | 24 + .../phoenix/compile/SaltedScanRangesTest.java | 239 + .../compile/ScanRangesIntersectTest.java | 4 +- .../apache/phoenix/compile/ScanRangesTest.java | 8 +- .../compile/StatementHintsCompilationTest.java | 8 +- .../TenantSpecificViewIndexCompileTest.java | 6 +- .../phoenix/compile/WhereOptimizerTest.java | 61 +- .../phoenix/execute/CorrelatePlanTest.java | 2 +- .../execute/LiteralResultIteratorPlanTest.java | 2 +- .../phoenix/execute/MutationStateTest.java | 4 +- .../phoenix/expression/LikeExpressionTest.java | 8 + .../BuiltinFunctionConstructorTest.java | 25 +- .../filter/DistinctPrefixFilterTest.java | 274 + .../phoenix/filter/SkipScanBigFilterTest.java | 12 +- .../index/write/TestParalleIndexWriter.java | 2 +- .../write/TestParalleWriterIndexCommitter.java | 2 +- .../phoenix/index/IndexMaintainerTest.java | 2 +- .../index/automated/MRJobSubmitterTest.java | 137 + .../iterate/AggregateResultScannerTest.java | 109 +- .../iterate/ConcatResultIteratorTest.java | 31 +- .../iterate/MaterializedResultIterators.java | 66 + ...owKeyOrderedAggregateResultIteratorTest.java | 149 + .../apache/phoenix/jdbc/PhoenixDriverTest.java | 10 +- .../phoenix/jdbc/PhoenixEmbeddedDriverTest.java | 6 +- .../phoenix/jdbc/SecureUserConnectionsTest.java | 382 + .../phoenix/mapreduce/BulkLoadToolTest.java | 5 +- .../ColumnInfoToStringEncoderDecoderTest.java | 4 +- .../util/PhoenixConfigurationUtilTest.java | 4 +- .../phoenix/memory/MemoryManagerTest.java | 93 +- .../java/org/apache/phoenix/query/BaseTest.java | 260 +- .../query/ParallelIteratorsSplitTest.java | 20 +- .../PhoenixStatsCacheRemovalListenerTest.java | 45 + .../org/apache/phoenix/query/QueryPlanTest.java | 30 +- .../phoenix/schema/PMetaDataImplTest.java | 102 +- .../apache/phoenix/schema/SortOrderTest.java | 2 - .../org/apache/phoenix/util/DateUtilTest.java | 25 + .../org/apache/phoenix/util/JDBCUtilTest.java | 8 + .../apache/phoenix/util/MetaDataUtilTest.java | 36 + .../phoenix/util/PhoenixEncodeDecodeTest.java | 4 +- .../util/TenantIdByteConversionTest.java | 2 +- .../java/org/apache/phoenix/util/TestUtil.java | 97 +- .../test/resources/hadoop-metrics2.properties | 18 +- .../src/test/resources/log4j.properties | 2 + phoenix-flume/pom.xml | 14 +- .../org/apache/phoenix/flume/PhoenixSinkIT.java | 17 +- .../phoenix/flume/RegexEventSerializerIT.java | 16 +- phoenix-hive/pom.xml | 162 + .../apache/phoenix/hive/HivePhoenixStoreIT.java | 303 + .../org/apache/phoenix/hive/HiveTestUtil.java | 1296 +++ .../apache/phoenix/hive/PhoenixMetaHook.java | 246 + .../phoenix/hive/PhoenixRecordUpdater.java | 336 + .../org/apache/phoenix/hive/PhoenixRow.java | 64 + .../org/apache/phoenix/hive/PhoenixRowKey.java | 69 + .../org/apache/phoenix/hive/PhoenixSerDe.java | 159 + .../apache/phoenix/hive/PhoenixSerializer.java | 169 + .../phoenix/hive/PhoenixStorageHandler.java | 212 + .../PhoenixStorageHandlerConstants.java | 108 + .../hive/mapreduce/PhoenixInputFormat.java | 269 + .../hive/mapreduce/PhoenixInputSplit.java | 160 + .../hive/mapreduce/PhoenixOutputFormat.java | 112 + .../hive/mapreduce/PhoenixRecordReader.java | 216 + .../hive/mapreduce/PhoenixRecordWriter.java | 355 + .../hive/mapreduce/PhoenixResultWritable.java | 211 + .../AbstractPhoenixObjectInspector.java | 59 + .../PhoenixBinaryObjectInspector.java | 58 + .../PhoenixBooleanObjectInspector.java | 50 + .../PhoenixByteObjectInspector.java | 54 + .../PhoenixCharObjectInspector.java | 51 + .../PhoenixDateObjectInspector.java | 63 + .../PhoenixDecimalObjectInspector.java | 63 + .../PhoenixDoubleObjectInspector.java | 54 + .../PhoenixFloatObjectInspector.java | 55 + .../PhoenixIntObjectInspector.java | 51 + .../PhoenixListObjectInspector.java | 105 + .../PhoenixLongObjectInspector.java | 51 + .../PhoenixObjectInspectorFactory.java | 148 + .../PhoenixShortObjectInspector.java | 51 + .../PhoenixStringObjectInspector.java | 72 + .../PhoenixTimestampObjectInspector.java | 61 + .../hive/ppd/PhoenixPredicateDecomposer.java | 82 + .../ppd/PhoenixPredicateDecomposerManager.java | 83 + .../hive/ql/index/IndexPredicateAnalyzer.java | 523 + .../hive/ql/index/IndexSearchCondition.java | 143 + .../hive/ql/index/PredicateAnalyzerFactory.java | 40 + .../phoenix/hive/query/PhoenixQueryBuilder.java | 760 ++ .../hive/util/PhoenixConnectionUtil.java | 97 + .../hive/util/PhoenixStorageHandlerUtil.java | 278 + .../apache/phoenix/hive/util/PhoenixUtil.java | 210 + phoenix-pherf/pom.xml | 317 +- .../apache/phoenix/pherf/ResultBaseTestIT.java | 4 +- .../apache/phoenix/pherf/SchemaReaderIT.java | 5 +- .../phoenix/pherf/result/ResultManager.java | 11 +- .../pherf/result/impl/ImageResultHandler.java | 126 - .../src/test/resources/pherf.test.properties | 60 +- phoenix-pig/pom.xml | 10 +- .../java/org/apache/phoenix/pig/BasePigIT.java | 6 +- .../phoenix/pig/PhoenixHBaseLoaderIT.java | 6 +- .../phoenix/pig/PhoenixHBaseStorerIT.java | 4 +- .../apache/phoenix/pig/PhoenixHBaseLoader.java | 4 +- .../phoenix/pig/util/PhoenixPigSchemaUtil.java | 4 +- .../pig/util/QuerySchemaParserFunction.java | 4 +- .../pig/util/SqlQueryToColumnInfoFunction.java | 4 +- .../pig/util/TableSchemaParserFunction.java | 4 +- .../pig/util/PhoenixPigSchemaUtilTest.java | 4 +- .../pig/util/QuerySchemaParserFunctionTest.java | 4 +- .../util/SqlQueryToColumnInfoFunctionTest.java | 4 +- .../pig/util/TableSchemaParserFunctionTest.java | 4 +- phoenix-protocol/src/main/MetaDataService.proto | 54 +- phoenix-protocol/src/main/PFunction.proto | 2 - phoenix-protocol/src/main/PGuidePosts.proto | 4 +- phoenix-protocol/src/main/PSchema.proto | 28 + phoenix-protocol/src/main/PTable.proto | 9 +- .../src/main/ServerCacheFactory.proto | 2 - .../src/main/ServerCachingService.proto | 2 - phoenix-queryserver-client/pom.xml | 187 + .../phoenix/queryserver/client/Driver.java | 49 + .../queryserver/client/SqllineWrapper.java | 87 + .../queryserver/client/ThinClientUtil.java | 42 + .../resources/META-INF/services/java.sql.Driver | 1 + .../org-apache-phoenix-remote-jdbc.properties | 25 + phoenix-queryserver/pom.xml | 170 + .../src/build/query-server-runnable.xml | 52 + .../phoenix/end2end/QueryServerBasicsIT.java | 164 + .../phoenix/end2end/QueryServerThread.java | 45 + .../src/it/resources/log4j.properties | 63 + .../apache/phoenix/queryserver/server/Main.java | 337 + .../queryserver/server/PhoenixMetaFactory.java | 28 + .../server/PhoenixMetaFactoryImpl.java | 76 + .../apache/phoenix/DriverCohabitationTest.java | 65 + .../server/PhoenixDoAsCallbackTest.java | 89 + phoenix-server-client/pom.xml | 66 - phoenix-server-client/src/build/thin-client.xml | 49 - .../phoenix/queryserver/client/Driver.java | 49 - .../queryserver/client/ThinClientUtil.java | 42 - .../resources/META-INF/services/java.sql.Driver | 1 - .../org-apache-phoenix-remote-jdbc.properties | 25 - phoenix-server/pom.xml | 195 +- .../src/build/query-server-runnable.xml | 52 - .../phoenix/end2end/QueryServerBasicsIT.java | 157 - .../phoenix/end2end/QueryServerThread.java | 45 - .../src/it/resources/log4j.properties | 63 - .../apache/phoenix/queryserver/server/Main.java | 236 - .../queryserver/server/PhoenixMetaFactory.java | 28 - .../server/PhoenixMetaFactoryImpl.java | 76 - .../apache/phoenix/DriverCohabitationTest.java | 65 - phoenix-spark/README.md | 19 +- phoenix-spark/pom.xml | 4 +- phoenix-spark/src/it/resources/setup.sql | 6 + .../apache/phoenix/spark/PhoenixSparkIT.scala | 86 +- .../apache/phoenix/spark/DefaultSource.scala | 3 +- .../org/apache/phoenix/spark/PhoenixRDD.scala | 27 +- .../apache/phoenix/spark/PhoenixRelation.scala | 34 +- phoenix-tracing-webapp/pom.xml | 2 +- .../src/main/webapp/js/api/chart-model.js | 20 +- .../src/main/webapp/js/app.js | 20 +- .../src/main/webapp/js/config/chart-config.js | 20 +- .../js/controllers/accordion-controllers.js | 18 + .../controllers/dependency-tree-controllers.js | 20 +- .../webapp/js/controllers/list-controllers.js | 20 +- .../webapp/js/controllers/search-controllers.js | 20 +- .../js/controllers/timeline-controllers.js | 20 +- .../js/controllers/trace-count-controllers.js | 20 +- .../trace-distribution-controllers.js | 20 +- .../js/factories/statement-factory-config.js | 20 +- .../webapp/js/factories/statement-factory.js | 20 +- .../js/services/generate-statement-service.js | 20 +- .../src/test/webapp/js/specs/app-route-spec.js | 20 +- .../test/webapp/js/specs/timeline-ctrl-spec.js | 20 +- .../webapp/js/specs/trace-list-ctrl-spec.js | 20 +- .../webapp/js/specs/tracing-app-ctrl-spec.js | 20 +- pom.xml | 324 +- 630 files changed, 45460 insertions(+), 16145 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/a9526a94/phoenix-core/pom.xml ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/a9526a94/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java index 46bcaa0,0000000..46a3053 mode 100644,000000..100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java @@@ -1,345 -1,0 +1,346 @@@ +package org.apache.phoenix.calcite; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + +import org.apache.calcite.jdbc.CalciteSchema; +import org.apache.calcite.linq4j.tree.Expression; +import org.apache.calcite.materialize.MaterializationService; +import org.apache.calcite.schema.*; +import org.apache.calcite.schema.impl.ViewTable; +import org.apache.phoenix.compile.ColumnResolver; +import org.apache.phoenix.compile.FromCompiler; +import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData; +import org.apache.phoenix.parse.ColumnDef; +import org.apache.phoenix.parse.NamedTableNode; +import org.apache.phoenix.parse.TableName; +import org.apache.phoenix.schema.MetaDataClient; +import org.apache.phoenix.schema.PColumn; +import org.apache.phoenix.schema.PTable; +import org.apache.phoenix.schema.PTable.ViewType; +import org.apache.phoenix.schema.PTableImpl; +import org.apache.phoenix.schema.PTableType; +import org.apache.phoenix.schema.TableNotFoundException; +import org.apache.phoenix.schema.TableRef; +import org.apache.phoenix.util.IndexUtil; +import org.apache.phoenix.util.SchemaUtil; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +/** + * Implementation of Calcite's {@link Schema} SPI for Phoenix. + * + * TODO + * 1) change this to non-caching mode?? + * 2) how to deal with define indexes and views since they require a CalciteSchema + * instance?? + * + */ +public class PhoenixSchema implements Schema { + public static final Factory FACTORY = new Factory(); + + public final PhoenixConnection pc; + + protected final String name; + protected final String schemaName; + protected final SchemaPlus parentSchema; + protected final MetaDataClient client; + + protected final Map<String, Schema> subSchemas; + protected final Map<String, Table> tables; + protected final Map<String, Function> views; + protected final Set<TableRef> viewTables; + + protected PhoenixSchema(String name, String schemaName, + SchemaPlus parentSchema, PhoenixConnection pc) { + this.name = name; + this.schemaName = schemaName; + this.parentSchema = parentSchema; + this.pc = pc; + this.client = new MetaDataClient(pc); + this.subSchemas = Maps.newHashMap(); + this.tables = Maps.newHashMap(); + this.views = Maps.newHashMap(); + this.viewTables = Sets.newHashSet(); + } + + private static Schema create(SchemaPlus parentSchema, + String name, Map<String, Object> operand) { + String url = (String) operand.get("url"); + final Properties properties = new Properties(); + for (Map.Entry<String, Object> entry : operand.entrySet()) { + properties.setProperty(entry.getKey(), String.valueOf(entry.getValue())); + } + try { + Class.forName("org.apache.phoenix.jdbc.PhoenixDriver"); + final Connection connection = + DriverManager.getConnection(url, properties); + final PhoenixConnection phoenixConnection = + connection.unwrap(PhoenixConnection.class); + return new PhoenixSchema(name, null, parentSchema, phoenixConnection); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + @Override + public Table getTable(String name) { + Table table = tables.get(name); + if (table != null) { + return table; + } + + try { + ColumnResolver x = FromCompiler.getResolver( + NamedTableNode.create( + null, + TableName.create(schemaName, name), + ImmutableList.<ColumnDef>of()), pc); + final List<TableRef> tables = x.getTables(); + assert tables.size() == 1; + TableRef tableRef = tables.get(0); + if (!isView(tableRef.getTable())) { + tableRef = fixTableMultiTenancy(tableRef); + table = new PhoenixTable(pc, tableRef); + } + } catch (TableNotFoundException e) { + } catch (SQLException e) { + throw new RuntimeException(e); + } + + if (table == null) { + table = resolveSequence(name); + } + + if (table != null) { + tables.put(name, table); + } + return table; + } + + @Override + public Set<String> getTableNames() { + return tables.keySet(); + } + + @Override + public Collection<Function> getFunctions(String name) { + Function func = views.get(name); + if (func != null) { + return ImmutableList.of(func); + } + + try { + ColumnResolver x = FromCompiler.getResolver( + NamedTableNode.create( + null, + TableName.create(schemaName, name), + ImmutableList.<ColumnDef>of()), pc); + final List<TableRef> tables = x.getTables(); + assert tables.size() == 1; + final TableRef tableRef = tables.get(0); + final PTable pTable = tableRef.getTable(); + if (isView(pTable)) { + String viewSql = pTable.getViewStatement(); + if (viewSql == null) { + viewSql = "select * from " + + SchemaUtil.getEscapedFullTableName( + pTable.getPhysicalName().getString()); + } + SchemaPlus schema = parentSchema.getSubSchema(this.name); + SchemaPlus viewSqlSchema = + this.schemaName == null ? schema : parentSchema; + func = ViewTable.viewMacro(schema, viewSql, + CalciteSchema.from(viewSqlSchema).path(null), + pTable.getViewType() == ViewType.UPDATABLE); + views.put(name, func); + viewTables.add(tableRef); + } + } catch (TableNotFoundException e) { + } catch (SQLException e) { + throw new RuntimeException(e); + } + + return func == null ? Collections.<Function>emptyList() : ImmutableList.of(func); + } + + @Override + public Set<String> getFunctionNames() { + return views.keySet(); + } + + @Override + public Schema getSubSchema(String name) { + if (schemaName != null) { + return null; + } + + Schema schema = subSchemas.get(name); + if (schema != null) { + return schema; + } + + schema = new PhoenixSchema(name, name, parentSchema.getSubSchema(this.name), pc); + subSchemas.put(name, schema); + return schema; + } + + @Override + public Set<String> getSubSchemaNames() { + return subSchemas.keySet(); + } + + @Override + public Expression getExpression(SchemaPlus parentSchema, String name) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isMutable() { + return true; + } + + @Override + public boolean contentsHaveChangedSince(long lastCheck, long now) { + return false; + } + + public void defineIndexesAsMaterializations() { + SchemaPlus schema = parentSchema.getSubSchema(this.name); + SchemaPlus viewSqlSchema = + this.schemaName == null ? schema : parentSchema; + CalciteSchema calciteSchema = CalciteSchema.from(schema); + List<String> path = CalciteSchema.from(viewSqlSchema).path(null); + try { + for (Table table : tables.values()) { + if (table instanceof PhoenixTable) { + TableRef tableRef = ((PhoenixTable) table).tableMapping.getTableRef(); + for (PTable index : tableRef.getTable().getIndexes()) { + TableRef indexTableRef = new TableRef(null, index, + tableRef.getTimeStamp(), tableRef.getLowerBoundTimeStamp(), + false); + addMaterialization(indexTableRef, path, calciteSchema); + } + } + } + for (TableRef tableRef : viewTables) { + final PTable pTable = tableRef.getTable(); + for (PTable index : pTable.getIndexes()) { + if (index.getParentName().equals(pTable.getName())) { + TableRef indexTableRef = new TableRef(null, index, + tableRef.getTimeStamp(), tableRef.getLowerBoundTimeStamp(), + false); + addMaterialization(indexTableRef, path, calciteSchema); + } + } + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + private void addMaterialization(TableRef indexTableRef, List<String> path, + CalciteSchema calciteSchema) throws SQLException { + indexTableRef = fixTableMultiTenancy(indexTableRef); + final PhoenixTable table = new PhoenixTable(pc, indexTableRef); + final PTable index = indexTableRef.getTable(); + tables.put(index.getTableName().getString(), table); + StringBuffer sb = new StringBuffer(); + sb.append("SELECT"); + for (PColumn column : table.getColumns()) { + String indexColumnName = column.getName().getString(); + String dataColumnName = IndexUtil.getDataColumnName(indexColumnName); + sb.append(",").append(SchemaUtil.getEscapedFullColumnName(dataColumnName)); + sb.append(" ").append(SchemaUtil.getEscapedFullColumnName(indexColumnName)); + } + sb.setCharAt(6, ' '); // replace first comma with space. + sb.append(" FROM ").append(SchemaUtil.getEscapedFullTableName(index.getParentName().getString())); + MaterializationService.instance().defineMaterialization( + calciteSchema, null, sb.toString(), path, index.getTableName().getString(), true, true); + } + + private boolean isView(PTable table) { + return table.getType() == PTableType.VIEW + && table.getViewType() != ViewType.MAPPED; + } + + private TableRef fixTableMultiTenancy(TableRef tableRef) throws SQLException { + if (pc.getTenantId() != null || !tableRef.getTable().isMultiTenant()) { + return tableRef; + } + PTable table = tableRef.getTable(); + table = PTableImpl.makePTable( + table.getTenantId(), table.getSchemaName(), table.getTableName(), table.getType(), table.getIndexState(), table.getTimeStamp(), + table.getSequenceNumber(), table.getPKName(), table.getBucketNum(), PTableImpl.getColumnsToClone(table), table.getParentSchemaName(), table.getParentTableName(), + table.getIndexes(), table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), + table.isWALDisabled(), false, table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(), - table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(), table.getTableStats(), table.getBaseColumnCount(), table.getIndexDisableTimestamp()); ++ table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(), table.getBaseColumnCount(), table.getIndexDisableTimestamp(), ++ table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema()); + return new TableRef(null, table, tableRef.getTimeStamp(), + tableRef.getLowerBoundTimeStamp(), tableRef.hasDynamicCols()); + } + + private PhoenixSequence resolveSequence(String name) { + try { + // FIXME: Do this the same way as resolving a table after PHOENIX-2489. + String tenantId = pc.getTenantId() == null ? null : pc.getTenantId().getString(); + String q = "select 1 from " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE + + " where " + PhoenixDatabaseMetaData.SEQUENCE_SCHEMA + + (schemaName == null ? " is null" : " = '" + schemaName + "'") + + " and " + PhoenixDatabaseMetaData.SEQUENCE_NAME + + " = '" + name + "'" + + " and " + PhoenixDatabaseMetaData.TENANT_ID + + (tenantId == null ? " is null" : " = '" + tenantId + "'"); + ResultSet rs = pc.createStatement().executeQuery(q); + if (rs.next()) { + return new PhoenixSequence(schemaName, name, pc); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + + return null; + } + + /** Schema factory that creates a + * {@link org.apache.phoenix.calcite.PhoenixSchema}. + * This allows you to create a Phoenix schema inside a model.json file. + * + * <pre>{@code + * { + * version: '1.0', + * defaultSchema: 'HR', + * schemas: [ + * { + * name: 'HR', + * type: 'custom', + * factory: 'org.apache.phoenix.calcite.PhoenixSchema.Factory', + * operand: { + * url: "jdbc:phoenix:localhost", + * user: "scott", + * password: "tiger" + * } + * } + * ] + * } + * }</pre> + */ + public static class Factory implements SchemaFactory { + public Schema create(SchemaPlus parentSchema, String name, Map<String, Object> operand) { + return PhoenixSchema.create(parentSchema, name, operand); + } + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/a9526a94/phoenix-core/src/main/java/org/apache/phoenix/calcite/TableMapping.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/main/java/org/apache/phoenix/calcite/TableMapping.java index ccf460f,0000000..a8dd9d2 mode 100644,000000..100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/TableMapping.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/TableMapping.java @@@ -1,368 -1,0 +1,369 @@@ +package org.apache.phoenix.calcite; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.apache.calcite.plan.RelOptUtil.InputFinder; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.util.ImmutableBitSet; +import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.io.ImmutableBytesWritable; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.Pair; +import org.apache.hadoop.io.WritableUtils; +import org.apache.phoenix.compile.ColumnProjector; +import org.apache.phoenix.compile.ExpressionProjector; +import org.apache.phoenix.compile.RowProjector; +import org.apache.phoenix.compile.TupleProjectionCompiler; +import org.apache.phoenix.coprocessor.BaseScannerRegionObserver; +import org.apache.phoenix.execute.TupleProjector; +import org.apache.phoenix.expression.ColumnExpression; +import org.apache.phoenix.expression.Expression; +import org.apache.phoenix.expression.LiteralExpression; +import org.apache.phoenix.index.IndexMaintainer; +import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.schema.ColumnRef; +import org.apache.phoenix.schema.PColumn; +import org.apache.phoenix.schema.PName; +import org.apache.phoenix.schema.PNameFactory; +import org.apache.phoenix.schema.PTable; +import org.apache.phoenix.schema.PTableImpl; +import org.apache.phoenix.schema.PTableType; +import org.apache.phoenix.schema.ProjectedColumn; +import org.apache.phoenix.schema.TableRef; +import org.apache.phoenix.schema.KeyValueSchema.KeyValueSchemaBuilder; +import org.apache.phoenix.schema.PTable.IndexType; +import org.apache.phoenix.util.ByteUtil; +import org.apache.phoenix.util.IndexUtil; +import org.apache.phoenix.util.MetaDataUtil; +import org.apache.phoenix.util.SchemaUtil; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + +public class TableMapping { + private final TableRef tableRef; + private final TableRef dataTableRef; + private final List<PColumn> mappedColumns; + private final int extendedColumnsOffset; + private final TableRef extendedTableRef; + + public TableMapping(PTable table) { + this.tableRef = new TableRef(table); + this.dataTableRef = null; + this.mappedColumns = getMappedColumns(table); + this.extendedColumnsOffset = mappedColumns.size(); + this.extendedTableRef = null; + } + + public TableMapping(TableRef tableRef, TableRef dataTableRef, boolean extend) throws SQLException { + this.tableRef = tableRef; + this.dataTableRef = dataTableRef; + if (!extend) { + this.mappedColumns = getMappedColumns(tableRef.getTable()); + this.extendedColumnsOffset = mappedColumns.size(); + this.extendedTableRef = null; + } else { + this.mappedColumns = Lists.newArrayList(); + this.mappedColumns.addAll(getMappedColumns(tableRef.getTable())); + this.extendedColumnsOffset = mappedColumns.size(); + Set<String> names = Sets.newHashSet(); + for (PColumn column : this.mappedColumns) { + names.add(column.getName().getString()); + } + PTable dataTable = dataTableRef.getTable(); + List<PColumn> projectedColumns = new ArrayList<PColumn>(); + for (PColumn sourceColumn : dataTable.getColumns()) { + if (!SchemaUtil.isPKColumn(sourceColumn)) { + String colName = IndexUtil.getIndexColumnName(sourceColumn); + if (!names.contains(colName)) { + ColumnRef sourceColumnRef = + new ColumnRef(dataTableRef, sourceColumn.getPosition()); + PColumn column = new ProjectedColumn(PNameFactory.newName(colName), + sourceColumn.getFamilyName(), projectedColumns.size(), + sourceColumn.isNullable(), sourceColumnRef); + projectedColumns.add(column); + } + } + } + this.mappedColumns.addAll(projectedColumns); + PTable extendedTable = PTableImpl.makePTable(dataTable.getTenantId(), + TupleProjectionCompiler.PROJECTED_TABLE_SCHEMA, dataTable.getName(), + PTableType.PROJECTED, null, dataTable.getTimeStamp(), + dataTable.getSequenceNumber(), dataTable.getPKName(), null, + projectedColumns, null, null, Collections.<PTable>emptyList(), + dataTable.isImmutableRows(), Collections.<PName>emptyList(), null, null, + dataTable.isWALDisabled(), false, dataTable.getStoreNulls(), + dataTable.getViewType(), null, null, dataTable.rowKeyOrderOptimizable(), + dataTable.isTransactional(), dataTable.getUpdateCacheFrequency(), - dataTable.getIndexDisableTimestamp()); ++ dataTable.getIndexDisableTimestamp(), dataTable.isNamespaceMapped(), ++ dataTable.getAutoPartitionSeqName(), dataTable.isAppendOnlySchema()); + this.extendedTableRef = new TableRef(extendedTable); + } + } + + public TableRef getTableRef() { + return tableRef; + } + + public PTable getPTable() { + return tableRef.getTable(); + } + + public TableRef getDataTableRef() { + return dataTableRef; + } + + public List<PColumn> getMappedColumns() { + return mappedColumns; + } + + public boolean hasExtendedColumns() { + return extendedTableRef != null; + } + + public ColumnExpression newColumnExpression(int index) { + ColumnRef colRef = new ColumnRef( + index < extendedColumnsOffset ? tableRef : extendedTableRef, + this.mappedColumns.get(index).getPosition()); + return colRef.newColumnExpression(); + } + + public ImmutableBitSet getDefaultExtendedColumnRef() { + return ImmutableBitSet.range(extendedColumnsOffset, mappedColumns.size()); + } + + public ImmutableBitSet getExtendedColumnRef(List<RexNode> exprs) { + if (!hasExtendedColumns()) { + return ImmutableBitSet.of(); + } + + ImmutableBitSet.Builder builder = ImmutableBitSet.builder(); + for (RexNode expr : exprs) { + builder.addAll(InputFinder.analyze(expr).inputBitSet.build()); + } + for (int i = 0; i < extendedColumnsOffset; i++) { + builder.clear(i); + } + return builder.build(); + } + + public Pair<Integer, Integer> getExtendedColumnReferenceCount(ImmutableBitSet columnRef) { + Set<String> cf = Sets.newHashSet(); + int columnCount = 0; + for (int i = extendedColumnsOffset; i < mappedColumns.size(); i++) { + if (columnRef.get(i)) { + PColumn dataColumn = ((ProjectedColumn) mappedColumns.get(i)) + .getSourceColumnRef().getColumn(); + cf.add(dataColumn.getFamilyName().getString()); + columnCount++; + } + } + return new Pair<Integer, Integer>(cf.size(), columnCount); + } + + public PTable createProjectedTable(boolean retainPKColumns) { + List<ColumnRef> sourceColumnRefs = Lists.<ColumnRef> newArrayList(); + List<PColumn> columns = retainPKColumns ? + tableRef.getTable().getColumns() : mappedColumns.subList(0, extendedColumnsOffset); + for (PColumn column : columns) { + sourceColumnRefs.add(new ColumnRef(tableRef, column.getPosition())); + } + if (extendedColumnsOffset < mappedColumns.size()) { + for (PColumn column : mappedColumns.subList(extendedColumnsOffset, mappedColumns.size())) { + sourceColumnRefs.add(new ColumnRef(extendedTableRef, column.getPosition())); + } + } + + try { + return TupleProjectionCompiler.createProjectedTable(tableRef, sourceColumnRefs, retainPKColumns); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + public TupleProjector createTupleProjector(boolean retainPKColumns) { + KeyValueSchemaBuilder builder = new KeyValueSchemaBuilder(0); + List<Expression> exprs = Lists.<Expression> newArrayList(); + for (int i = 0; i < mappedColumns.size(); i++) { + if (!SchemaUtil.isPKColumn(mappedColumns.get(i)) || !retainPKColumns) { + Expression expr = newColumnExpression(i); + exprs.add(expr); + builder.addField(expr); + } + } + + return new TupleProjector(builder.build(), exprs.toArray(new Expression[exprs.size()])); + } + + public RowProjector createRowProjector() { + List<ColumnProjector> columnProjectors = Lists.<ColumnProjector>newArrayList(); + for (int i = 0; i < mappedColumns.size(); i++) { + PColumn column = mappedColumns.get(i); + Expression expr = newColumnExpression(i); // Do not use column.position() here. + columnProjectors.add(new ExpressionProjector(column.getName().getString(), tableRef.getTable().getName().getString(), expr, false)); + } + // TODO get estimate row size + return new RowProjector(columnProjectors, 0, false); + } + + public void setupScanForExtendedTable(Scan scan, ImmutableBitSet extendedColumnRef, + PhoenixConnection connection) throws SQLException { + if (extendedTableRef == null || extendedColumnRef.isEmpty()) { + return; + } + + TableRef dataTableRef = null; + List<PColumn> dataColumns = Lists.newArrayList(); + KeyValueSchemaBuilder builder = new KeyValueSchemaBuilder(0); + List<Expression> exprs = Lists.<Expression> newArrayList(); + for (int i = extendedColumnsOffset; i < mappedColumns.size(); i++) { + ProjectedColumn column = (ProjectedColumn) mappedColumns.get(i); + builder.addField(column); + if (extendedColumnRef.get(i)) { + dataColumns.add(column.getSourceColumnRef().getColumn()); + exprs.add(column.getSourceColumnRef().newColumnExpression()); + if (dataTableRef == null) { + dataTableRef = column.getSourceColumnRef().getTableRef(); + } + } else { + exprs.add(LiteralExpression.newConstant(null)); + } + } + if (dataColumns.isEmpty()) { + return; + } + + // Set data columns to be join back from data table. + serializeDataTableColumnsToJoin(scan, dataColumns); + // Set tuple projector of the data columns. + TupleProjector projector = new TupleProjector(builder.build(), exprs.toArray(new Expression[exprs.size()])); + TupleProjector.serializeProjectorIntoScan(scan, projector, IndexUtil.INDEX_PROJECTOR); + PTable dataTable = dataTableRef.getTable(); + // Set index maintainer of the local index. + serializeIndexMaintainerIntoScan(scan, dataTable, connection); + // Set view constants if exists. + serializeViewConstantsIntoScan(scan, dataTable); + } + + private static void serializeDataTableColumnsToJoin(Scan scan, List<PColumn> dataColumns) { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + try { + DataOutputStream output = new DataOutputStream(stream); + WritableUtils.writeVInt(output, dataColumns.size()); + for (PColumn column : dataColumns) { + Bytes.writeByteArray(output, column.getFamilyName().getBytes()); + Bytes.writeByteArray(output, column.getName().getBytes()); + } + scan.setAttribute(BaseScannerRegionObserver.DATA_TABLE_COLUMNS_TO_JOIN, stream.toByteArray()); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + stream.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + private void serializeIndexMaintainerIntoScan(Scan scan, PTable dataTable, PhoenixConnection connection) throws SQLException { + PName name = getPTable().getName(); + List<PTable> indexes = Lists.newArrayListWithExpectedSize(1); + for (PTable index : dataTable.getIndexes()) { + if (index.getName().equals(name) && index.getIndexType() == IndexType.LOCAL) { + indexes.add(index); + break; + } + } + ImmutableBytesWritable ptr = new ImmutableBytesWritable(); + IndexMaintainer.serialize(dataTable, ptr, indexes, connection); + scan.setAttribute(BaseScannerRegionObserver.LOCAL_INDEX_BUILD, ByteUtil.copyKeyBytesIfNecessary(ptr)); + if (dataTable.isTransactional()) { + scan.setAttribute(BaseScannerRegionObserver.TX_STATE, connection.getMutationState().encodeTransaction()); + } + } + + private static void serializeViewConstantsIntoScan(Scan scan, PTable dataTable) { + int dataPosOffset = (dataTable.getBucketNum() != null ? 1 : 0) + (dataTable.isMultiTenant() ? 1 : 0); + int nViewConstants = 0; + if (dataTable.getType() == PTableType.VIEW) { + ImmutableBytesWritable ptr = new ImmutableBytesWritable(); + List<PColumn> dataPkColumns = dataTable.getPKColumns(); + for (int i = dataPosOffset; i < dataPkColumns.size(); i++) { + PColumn dataPKColumn = dataPkColumns.get(i); + if (dataPKColumn.getViewConstant() != null) { + nViewConstants++; + } + } + if (nViewConstants > 0) { + byte[][] viewConstants = new byte[nViewConstants][]; + int j = 0; + for (int i = dataPosOffset; i < dataPkColumns.size(); i++) { + PColumn dataPkColumn = dataPkColumns.get(i); + if (dataPkColumn.getViewConstant() != null) { + if (IndexUtil.getViewConstantValue(dataPkColumn, ptr)) { + viewConstants[j++] = ByteUtil.copyKeyBytesIfNecessary(ptr); + } else { + throw new IllegalStateException(); + } + } + } + serializeViewConstantsIntoScan(viewConstants, scan); + } + } + } + + private static void serializeViewConstantsIntoScan(byte[][] viewConstants, Scan scan) { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + try { + DataOutputStream output = new DataOutputStream(stream); + WritableUtils.writeVInt(output, viewConstants.length); + for (byte[] viewConstant : viewConstants) { + Bytes.writeByteArray(output, viewConstant); + } + scan.setAttribute(BaseScannerRegionObserver.VIEW_CONSTANTS, stream.toByteArray()); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + stream.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + private static List<PColumn> getMappedColumns(PTable pTable) { + if (pTable.getBucketNum() == null + && !pTable.isMultiTenant() + && pTable.getViewIndexId() == null) { + return pTable.getColumns(); + } + + List<PColumn> columns = Lists.newArrayList(pTable.getColumns()); + if (pTable.getViewIndexId() != null) { + for (Iterator<PColumn> iter = columns.iterator(); iter.hasNext();) { - if (iter.next().getName().getString().equals(MetaDataUtil.VIEW_INDEX_ID_COLUMN_NAME)) { ++ if (iter.next().getName().getString().equals(MetaDataUtil.getViewIndexIdColumnName())) { + iter.remove(); + break; + } + } + } + if (pTable.isMultiTenant()) { + columns.remove(pTable.getBucketNum() == null ? 0 : 1); + } + if (pTable.getBucketNum() != null) { + columns.remove(0); + } + + return columns; + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/a9526a94/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRelImplementorImpl.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRelImplementorImpl.java index 96651e9,0000000..fa4649b mode 100644,000000..100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRelImplementorImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRelImplementorImpl.java @@@ -1,140 -1,0 +1,140 @@@ +package org.apache.phoenix.calcite.rel; + +import java.sql.SQLException; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import org.apache.phoenix.calcite.PhoenixSequence; +import org.apache.phoenix.calcite.TableMapping; +import org.apache.phoenix.compile.QueryPlan; +import org.apache.phoenix.compile.SequenceManager; +import org.apache.phoenix.compile.SequenceValueExpression; +import org.apache.phoenix.coprocessor.MetaDataProtocol; +import org.apache.phoenix.execute.RuntimeContext; +import org.apache.phoenix.execute.TupleProjector; +import org.apache.phoenix.expression.BindParameterExpression; +import org.apache.phoenix.expression.ColumnExpression; +import org.apache.phoenix.expression.CorrelateVariableFieldAccessExpression; +import org.apache.phoenix.expression.Expression; +import org.apache.phoenix.parse.ParseNodeFactory; +import org.apache.phoenix.parse.SequenceValueParseNode; +import org.apache.phoenix.parse.TableName; +import org.apache.phoenix.schema.KeyValueSchema; +import org.apache.phoenix.schema.PColumn; +import org.apache.phoenix.schema.PColumnImpl; +import org.apache.phoenix.schema.PName; +import org.apache.phoenix.schema.PNameFactory; +import org.apache.phoenix.schema.PTable; +import org.apache.phoenix.schema.PTableImpl; +import org.apache.phoenix.schema.PTableType; +import org.apache.phoenix.schema.types.PDataType; +import com.google.common.collect.Lists; + +public class PhoenixRelImplementorImpl implements PhoenixRelImplementor { + private final RuntimeContext runtimeContext; + private Stack<ImplementorContext> contextStack; + private SequenceManager sequenceManager; + private TableMapping tableMapping; + + public PhoenixRelImplementorImpl(RuntimeContext runtimeContext) { + this.runtimeContext = runtimeContext; + this.contextStack = new Stack<ImplementorContext>(); + } + + @Override + public QueryPlan visitInput(int i, PhoenixQueryRel input) { + return input.implement(this); + } + + @Override + public ColumnExpression newColumnExpression(int index) { + return tableMapping.newColumnExpression(index); + } + + @SuppressWarnings("rawtypes") + @Override + public Expression newBindParameterExpression(int index, PDataType type, Integer maxLength) { + return new BindParameterExpression(index, type, maxLength, runtimeContext); + } + + @SuppressWarnings("rawtypes") + @Override + public Expression newFieldAccessExpression(String variableId, int index, PDataType type) { + Expression fieldAccessExpr = runtimeContext.getCorrelateVariable(variableId).newExpression(index); + return new CorrelateVariableFieldAccessExpression(runtimeContext, variableId, fieldAccessExpr); + } + + @Override + public SequenceValueExpression newSequenceExpression(PhoenixSequence seq, SequenceValueParseNode.Op op) { + PName tenantName = seq.pc.getTenantId(); + TableName tableName = TableName.create(seq.schemaName, seq.sequenceName); + try { + return sequenceManager.newSequenceReference(tenantName, tableName, null, op); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + @Override + public RuntimeContext getRuntimeContext() { + return runtimeContext; + } + + @Override + public void setTableMapping(TableMapping tableMapping) { + this.tableMapping = tableMapping; + } + + @Override + public TableMapping getTableMapping() { + return this.tableMapping; + } + + @Override + public void setSequenceManager(SequenceManager sequenceManager) { + this.sequenceManager = sequenceManager; + } + + @Override + public void pushContext(ImplementorContext context) { + this.contextStack.push(context); + } + + @Override + public ImplementorContext popContext() { + return contextStack.pop(); + } + + @Override + public ImplementorContext getCurrentContext() { + return contextStack.peek(); + } + + @Override + public TupleProjector project(List<Expression> exprs) { + KeyValueSchema.KeyValueSchemaBuilder builder = new KeyValueSchema.KeyValueSchemaBuilder(0); + List<PColumn> columns = Lists.<PColumn>newArrayList(); + for (int i = 0; i < exprs.size(); i++) { + String name = ParseNodeFactory.createTempAlias(); + Expression expr = exprs.get(i); + builder.addField(expr); + columns.add(new PColumnImpl(PNameFactory.newName(name), PNameFactory.newName(TupleProjector.VALUE_COLUMN_FAMILY), + expr.getDataType(), expr.getMaxLength(), expr.getScale(), expr.isNullable(), + i, expr.getSortOrder(), null, null, false, name, false, false)); + } + try { + PTable pTable = PTableImpl.makePTable(null, PName.EMPTY_NAME, PName.EMPTY_NAME, + PTableType.SUBQUERY, null, MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM, + null, null, columns, null, null, Collections.<PTable>emptyList(), + false, Collections.<PName>emptyList(), null, null, false, false, false, null, - null, null, true, false, 0, 0); ++ null, null, true, false, 0, 0, false, null, false); + this.setTableMapping(new TableMapping(pTable)); + } catch (SQLException e) { + throw new RuntimeException(e); + } + + return new TupleProjector(builder.build(), exprs.toArray(new Expression[exprs.size()])); + } + +}