├── .github └── workflows │ └── test.yaml ├── .gitignore ├── .gitmodules ├── .java-version ├── LICENSE ├── README.md ├── TPP.txt ├── artifact └── .gitkeep ├── cpp ├── .clang-format ├── .gitignore ├── CMakeLists.txt ├── Makefile ├── doc │ └── EnableAddressSanitizer.md ├── leak_suppress.txt ├── scripts │ ├── install_deps_ubuntu.sh │ ├── setup-helper-functions.sh │ ├── setup-velox-centos8.sh │ └── setup-velox-ubuntu.sh ├── src │ ├── CMakeLists.txt │ ├── JniHandle.cpp │ ├── JniHandle.h │ ├── NativeConfigs.cpp │ ├── NativeConfigs.h │ ├── PartitionOutputData.cpp │ ├── PartitionOutputData.h │ ├── TaskHandle.cpp │ ├── TaskHandle.h │ ├── TrinoBridge.cpp │ ├── TrinoBridge.h │ ├── TrinoExchangeSource.cpp │ ├── TrinoExchangeSource.h │ ├── functions │ │ ├── CMakeLists.txt │ │ ├── TpchPartitionFunction.cpp │ │ ├── TpchPartitionFunction.h │ │ ├── TrinoSumAggregate.cpp │ │ └── tests │ │ │ ├── CMakeLists.txt │ │ │ ├── TpchPartitionFunctionTest.cpp │ │ │ └── TrinoSumAggregateTest.cpp │ ├── protocol │ │ ├── Base64Util.cpp │ │ ├── Base64Util.h │ │ ├── CMakeLists.txt │ │ ├── DataSize.cpp │ │ ├── DataSize.h │ │ ├── Duration.cpp │ │ ├── Duration.h │ │ ├── Makefile │ │ ├── external │ │ │ └── json │ │ │ │ └── json.hpp │ │ ├── java-to-struct-json.py │ │ ├── license-header.py │ │ ├── license.header │ │ ├── protocol.yml │ │ ├── special │ │ │ ├── AggregationNodeStep.java │ │ │ ├── Block.cpp.inc │ │ │ ├── Block.hpp.inc │ │ │ ├── CatalogHandle.cpp.inc │ │ │ ├── CatalogHandle.hpp.inc │ │ │ ├── DataSize.cpp.inc │ │ │ ├── DataSize.hpp.inc │ │ │ ├── Distribution.java │ │ │ ├── Duration.cpp.inc │ │ │ ├── Duration.hpp.inc │ │ │ ├── GlutenConnectorTransactionHandle.cpp.inc │ │ │ ├── GlutenTpchTransactionHandle.cpp.inc │ │ │ ├── GlutenTpchTransactionHandle.hpp.inc │ │ │ ├── GlutenTupleDomain.hpp.inc │ │ │ ├── GlutenVariableReferenceExpression.hpp.inc │ │ │ ├── HivePartitioningHandle.java │ │ │ ├── HostAddress.hpp.inc │ │ │ ├── JsonEncodedSubclass.cpp.inc │ │ │ ├── OperatorInfo.cpp.inc │ │ │ ├── OperatorInfo.hpp.inc │ │ │ ├── OutputBufferInfo.java │ │ │ ├── SystemPartitioningHandle.java │ │ │ └── ValueEntry.hpp.inc │ │ ├── topological.py │ │ ├── trino_protocol-json-cpp.mustache │ │ ├── trino_protocol-json-hpp.mustache │ │ └── util.py │ ├── serialization │ │ ├── CMakeLists.txt │ │ ├── TrinoBuffer.h │ │ ├── TrinoBufferStream.cpp │ │ ├── TrinoBufferStream.h │ │ ├── TrinoByteStream.cpp │ │ ├── TrinoByteStream.h │ │ ├── TrinoSerializer.cpp │ │ ├── TrinoSerializer.h │ │ └── tests │ │ │ ├── CMakeLists.txt │ │ │ └── SerdeTest.cpp │ ├── tests │ │ ├── CMakeLists.txt │ │ ├── NativeConfigsTest.cpp │ │ └── PartitionOutputDataTest.cpp │ ├── types │ │ ├── .gitattributes │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── ParseTypeSignature.h │ │ ├── PrestoToVeloxExpr.cpp │ │ ├── PrestoToVeloxExpr.h │ │ ├── PrestoToVeloxQueryPlan.cpp │ │ ├── PrestoToVeloxQueryPlan.h │ │ ├── PrestoToVeloxSplit.cpp │ │ ├── PrestoToVeloxSplit.h │ │ ├── README.md │ │ ├── TrinoTaskId.h │ │ ├── TypeSignature.g4 │ │ ├── TypeSignatureTypeConverter.cpp │ │ ├── TypeSignatureTypeConverter.h │ │ ├── antlr │ │ │ ├── TypeSignature.interp │ │ │ ├── TypeSignature.tokens │ │ │ ├── TypeSignatureBaseVisitor.cpp │ │ │ ├── TypeSignatureBaseVisitor.h │ │ │ ├── TypeSignatureLexer.cpp │ │ │ ├── TypeSignatureLexer.h │ │ │ ├── TypeSignatureLexer.interp │ │ │ ├── TypeSignatureLexer.tokens │ │ │ ├── TypeSignatureParser.cpp │ │ │ ├── TypeSignatureParser.h │ │ │ ├── TypeSignatureVisitor.cpp │ │ │ └── TypeSignatureVisitor.h │ │ └── tests │ │ │ ├── CMakeLists.txt │ │ │ ├── PlanNodeConverterTest.cpp │ │ │ ├── RowExpressionConverterTest.cpp │ │ │ ├── TypeSignatureConverterTest.cpp │ │ │ ├── ValuesPipeTest.cpp │ │ │ └── VeloxSplitConverterTest.cpp │ └── utils │ │ ├── Counters.h │ │ ├── HttpClient.cpp │ │ ├── HttpClient.h │ │ ├── HttpConstants.h │ │ ├── JniUtils.cpp │ │ ├── JniUtils.h │ │ ├── ThreadUtils.cpp │ │ └── ThreadUtils.h ├── velox.patch └── velox_cast.patch ├── docs └── gluten-trino-arch.png ├── java ├── .mvn │ ├── extensions.xml │ ├── jvm.config │ ├── modernizer │ │ └── violations.xml │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── trino │ │ ├── connector │ │ └── StaticCatalogManager.java │ │ ├── execution │ │ ├── SqlTask.java │ │ ├── SqlTaskExecution.java │ │ ├── SqlTaskExecutionFactory.java │ │ ├── SqlTaskManager.java │ │ └── TaskExecution.java │ │ ├── jni │ │ ├── NativeLogger.java │ │ └── TrinoBridge.java │ │ ├── metadata │ │ ├── HandleJsonModule.java │ │ └── HandleResolver.java │ │ ├── plugin │ │ ├── hive │ │ │ ├── HiveColumnHandle.java │ │ │ ├── HiveSplit.java │ │ │ ├── HiveTableHandle.java │ │ │ ├── HiveTransactionHandle.java │ │ │ ├── metastore │ │ │ │ └── MetastoreUtil.java │ │ │ ├── protocol │ │ │ │ ├── GlutenBucketConversion.java │ │ │ │ ├── GlutenBucketFunctionType.java │ │ │ │ ├── GlutenCacheQuotaRequirement.java │ │ │ │ ├── GlutenCacheQuotaScope.java │ │ │ │ ├── GlutenDwrfEncryptionMetadata.java │ │ │ │ ├── GlutenEncryptionInformation.java │ │ │ │ ├── GlutenEncryptionMetadata.java │ │ │ │ ├── GlutenHiveBucketProperty.java │ │ │ │ ├── GlutenHiveColumnHandle.java │ │ │ │ ├── GlutenHiveFileSplit.java │ │ │ │ ├── GlutenHiveSplit.java │ │ │ │ ├── GlutenHiveTableHandle.java │ │ │ │ ├── GlutenHiveTransactionHandle.java │ │ │ │ ├── GlutenStorage.java │ │ │ │ └── GlutenTableToPartitionMapping.java │ │ │ ├── s3 │ │ │ │ ├── HiveS3Module.java │ │ │ │ ├── S3SecurityMappingConfigurationProvider.java │ │ │ │ └── TrinoS3ConfigurationInitializer.java │ │ │ ├── s3select │ │ │ │ └── S3SelectPushdown.java │ │ │ └── util │ │ │ │ └── InternalHiveSplitFactory.java │ │ └── tpch │ │ │ ├── TpchColumnHandle.java │ │ │ ├── TpchSplit.java │ │ │ ├── TpchTableHandle.java │ │ │ ├── TpchTransactionHandle.java │ │ │ └── protocol │ │ │ ├── GlutenTpchColumnHandle.java │ │ │ ├── GlutenTpchSplit.java │ │ │ ├── GlutenTpchTableHandle.java │ │ │ ├── GlutenTpchTableLayoutHandle.java │ │ │ └── GlutenTpchTransactionHandle.java │ │ ├── server │ │ ├── DevelopmentLoaderConfig.java │ │ ├── DevelopmentPluginsProvider.java │ │ ├── ServerConfig.java │ │ ├── ServerMainModule.java │ │ ├── ServerPluginsProvider.java │ │ ├── ServerPluginsProviderConfig.java │ │ └── TaskResource.java │ │ ├── spi │ │ ├── connector │ │ │ ├── ColumnHandle.java │ │ │ ├── ConnectorSplit.java │ │ │ ├── ConnectorTableHandle.java │ │ │ └── ConnectorTransactionHandle.java │ │ ├── predicate │ │ │ ├── GlutenMarker.java │ │ │ ├── SortedRangeSet.java │ │ │ └── ValueSet.java │ │ └── protocol │ │ │ ├── GlutenAllOrNoneValueSet.java │ │ │ ├── GlutenColumnHandle.java │ │ │ ├── GlutenConnectorSplit.java │ │ │ ├── GlutenConnectorTableHandle.java │ │ │ ├── GlutenConnectorTableLayoutHandle.java │ │ │ ├── GlutenConnectorTransactionHandle.java │ │ │ ├── GlutenDomain.java │ │ │ ├── GlutenEquatableValueSet.java │ │ │ ├── GlutenNodeSelectionStrategy.java │ │ │ ├── GlutenRange.java │ │ │ ├── GlutenSortedRangeSet.java │ │ │ ├── GlutenSubfield.java │ │ │ ├── GlutenSubfieldTokenizer.java │ │ │ ├── GlutenTupleDomain.java │ │ │ └── GlutenValueSet.java │ │ ├── split │ │ ├── EmptySplit.java │ │ └── RemoteSplit.java │ │ ├── sql │ │ └── planner │ │ │ └── PartitioningHandle.java │ │ └── velox │ │ ├── NativeConfigs.java │ │ ├── NativeTaskConfig.java │ │ ├── execution │ │ ├── HybridSqlTaskExecutionFactory.java │ │ ├── NativeExecutorModule.java │ │ ├── NativeSqlTaskExecution.java │ │ └── NativeSqlTaskExecutionManager.java │ │ └── protocol │ │ ├── ExpressionTranslator.java │ │ ├── GlutenAggregationNode.java │ │ ├── GlutenAssignUniqueId.java │ │ ├── GlutenAssignments.java │ │ ├── GlutenBuiltInFunctionHandle.java │ │ ├── GlutenCallExpression.java │ │ ├── GlutenCatalogProperties.java │ │ ├── GlutenConnectorId.java │ │ ├── GlutenConstantExpression.java │ │ ├── GlutenEmptySplit.java │ │ ├── GlutenEnforceSingleRowNode.java │ │ ├── GlutenExchangeNode.java │ │ ├── GlutenFilterNode.java │ │ ├── GlutenFunctionHandle.java │ │ ├── GlutenGroupIdNode.java │ │ ├── GlutenJoinNode.java │ │ ├── GlutenLimitNode.java │ │ ├── GlutenLocation.java │ │ ├── GlutenMarkDistinctNode.java │ │ ├── GlutenOrderingScheme.java │ │ ├── GlutenOutputNode.java │ │ ├── GlutenPartitioning.java │ │ ├── GlutenPartitioningHandle.java │ │ ├── GlutenPartitioningScheme.java │ │ ├── GlutenPlanFragment.java │ │ ├── GlutenPlanNode.java │ │ ├── GlutenProjectNode.java │ │ ├── GlutenRemoteSourceNode.java │ │ ├── GlutenRemoteSplit.java │ │ ├── GlutenRowExpression.java │ │ ├── GlutenScheduledSplit.java │ │ ├── GlutenSemiJoinNode.java │ │ ├── GlutenSignature.java │ │ ├── GlutenSortNode.java │ │ ├── GlutenSpecialFormExpression.java │ │ ├── GlutenSplit.java │ │ ├── GlutenSplitAssignment.java │ │ ├── GlutenTableHandle.java │ │ ├── GlutenTableScanNode.java │ │ ├── GlutenTopNNode.java │ │ ├── GlutenTopNRowNumberNode.java │ │ ├── GlutenValuesNode.java │ │ ├── GlutenVariableExpressionSerializer.java │ │ ├── GlutenVariableReferenceExpression.java │ │ ├── GlutenWindowNode.java │ │ ├── PlanFragmentTranslator.java │ │ ├── PlanNodeTranslator.java │ │ └── SplitAssignmentsMessage.java │ └── test │ ├── java │ └── io │ │ └── trino │ │ ├── execution │ │ └── TestSqlTaskManager.java │ │ ├── gluten │ │ └── tests │ │ │ ├── GlutenClient.java │ │ │ └── tpch │ │ │ └── TpchFuncTest.java │ │ ├── jni │ │ ├── TestTrinoBridge.java │ │ ├── TrinoBridgeGetMetrics.java │ │ └── TrinoBridgeSerializationTest.java │ │ └── plugin │ │ └── hive │ │ ├── HiveQueryRunner.java │ │ ├── TestHiveSplit.java │ │ └── TestHiveTableHandle.java │ └── resources │ └── io │ └── trino │ └── gluten │ └── tests │ └── tpch │ ├── q1.sql │ ├── q10.sql │ ├── q11.sql │ ├── q12.sql │ ├── q13.sql │ ├── q14.sql │ ├── q15.sql │ ├── q16.sql │ ├── q17.sql │ ├── q18.sql │ ├── q19.sql │ ├── q2.sql │ ├── q20.sql │ ├── q21.sql │ ├── q22.sql │ ├── q3.sql │ ├── q4.sql │ ├── q5.sql │ ├── q6.sql │ ├── q7.sql │ ├── q8.sql │ └── q9.sql ├── migrate.sh └── scripts ├── Dockerfile ├── build_all.sh ├── check.py ├── git-clang-format ├── run_tpch.sh └── util.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.ipr 3 | *.iws 4 | target/ 5 | /**/var/ 6 | **/trino-product-tests/**/var/ 7 | pom.xml.versionsBackup 8 | test-output/ 9 | test-reports/ 10 | /atlassian-ide-plugin.xml 11 | .idea 12 | .run 13 | .DS_Store 14 | .classpath 15 | .settings 16 | .project 17 | temp-testng-customsuite.xml 18 | test-output 19 | .externalToolBuilders 20 | *~ 21 | benchmark_outputs 22 | *.pyc 23 | *.class 24 | .checkstyle 25 | .mvn/timing.properties 26 | node_modules 27 | product-test-reports 28 | .vscode/ 29 | /gib-impacted.log 30 | /impacted-features.log 31 | .github/test-matrix.yaml 32 | .github/test-pt-matrix.yaml 33 | .github/bin/redshift/.cluster-identifier 34 | cmake-build-* 35 | trino-cpp/build 36 | **/trino_protocol.h 37 | **/trino_protocol.cpp 38 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cpp/velox"] 2 | path = cpp/velox 3 | url = https://github.com/facebookincubator/velox.git 4 | -------------------------------------------------------------------------------- /.java-version: -------------------------------------------------------------------------------- 1 | 17.0 2 | -------------------------------------------------------------------------------- /artifact/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oap-project/Gluten-Trino/e2c8171559d5268b8368776f9f93919006872419/artifact/.gitkeep -------------------------------------------------------------------------------- /cpp/.clang-format: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | --- 18 | BasedOnStyle: Google 19 | ColumnLimit: 90 20 | DerivePointerAlignment: false 21 | IncludeBlocks: Preserve 22 | -------------------------------------------------------------------------------- /cpp/.gitignore: -------------------------------------------------------------------------------- 1 | .cache 2 | build-* 3 | compile_commands.json 4 | src/protocol/trino_protocol.json 5 | dist/ 6 | antlr4-cpp-runtime/build/ 7 | antlr4-cpp-runtime/dist/ 8 | antlr4-cpp-runtime/run/ -------------------------------------------------------------------------------- /cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | message(STATUS "Building using CMake version: ${CMAKE_VERSION}") 3 | 4 | project(TrinoBridge) 5 | 6 | include(CTest) 7 | 8 | execute_process( 9 | COMMAND 10 | bash -c 11 | "( source ${CMAKE_CURRENT_SOURCE_DIR}/velox/scripts/setup-helper-functions.sh && echo -n $(get_cxx_flags $ENV{CPU_TARGET}))" 12 | OUTPUT_VARIABLE SCRIPT_CXX_FLAGS 13 | RESULT_VARIABLE COMMAND_STATUS) 14 | 15 | # Compiler options 16 | set(CMAKE_CXX_STANDARD 17) 17 | set(CMAKE_CXX_STANDARD_REQUIRED True) 18 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 19 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 20 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SCRIPT_CXX_FLAGS}") 21 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 22 | 23 | # Gluten-Trino options 24 | option(GLUTEN_TRINO_ENABLE_SANITIZER 25 | "Enable AddressSanitizer for Gluten-Trino." OFF) 26 | option(GLUTEN_TRINO_BUILDING_TESTS "Building tests for Gluten-Trino." ON) 27 | option(GLUTEN_TRINO_ENABLE_S3 "Enable S3 storage for Gluten-Trino." OFF) 28 | 29 | # Velox options 30 | add_compile_definitions(FOLLY_HAVE_INT128_T=1) 31 | set(VELOX_BUILD_TESTING OFF) 32 | set(VELOX_ENABLE_SPARK_FUNCTIONS OFF) 33 | set(VELOX_ENABLE_EXAMPLES OFF) 34 | set(VELOX_ENABLE_PARSE ON) 35 | set(VELOX_BUILD_TEST_UTILS ON) 36 | set(VELOX_ENABLE_PARQUET ON) 37 | set(VELOX_ENABLE_HDFS ON) 38 | 39 | if(GLUTEN_TRINO_ENABLE_S3) 40 | set(VELOX_ENABLE_S3 ON) 41 | add_definitions(-DENABLE_GLUTEN_TRINO_S3) 42 | else() 43 | set(VELOX_ENABLE_S3 OFF) 44 | endif(GLUTEN_TRINO_ENABLE_S3) 45 | 46 | set(XSIMD_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/_deps/xsimd-src/include/) 47 | include_directories(SYSTEM ${XSIMD_INCLUDE_DIRS}) 48 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 49 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/velox) 50 | include_directories(${CMAKE_BINARY_DIR}) 51 | 52 | add_subdirectory(velox) 53 | add_subdirectory(src) 54 | -------------------------------------------------------------------------------- /cpp/Makefile: -------------------------------------------------------------------------------- 1 | JOBS?=$(bash getconf _NPROCESSORS_CONF) 2 | 3 | .PHONY: depends sanitizer debug release clean 4 | 5 | clean: 6 | @ls | grep '^build-\(Debug\|Release\)' | xargs -r rm -r 7 | 8 | build: 9 | $(MAKE) velox-patch 10 | @mkdir -p build-$(BUILD_TYPE) && \ 11 | cmake -B build-$(BUILD_TYPE) -GNinja -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DGLUTEN_TRINO_ENABLE_SANITIZER=$(ENABLE_SANITIZER) 12 | cmake --build build-$(BUILD_TYPE) -j $(JOBS) 13 | 14 | debug: 15 | $(MAKE) build BUILD_TYPE=Debug ENABLE_SANITIZER=OFF 16 | 17 | debug-asn: 18 | $(MAKE) build BUILD_TYPE=Debug ENABLE_SANITIZER=ON 19 | 20 | release: 21 | $(MAKE) build BUILD_TYPE=Release ENABLE_SANITIZER=OFF 22 | 23 | release-debug: 24 | $(MAKE) build BUILD_TYPE=RelWithDebInfo ENABLE_SANITIZER=OFF 25 | 26 | depends: 27 | @mkdir -p _deps 28 | cd _deps && bash ../scripts/install_deps_ubuntu.sh 29 | rm -rf _deps 30 | 31 | sanitizer: 32 | echo 1 > /proc/sys/vm/overcommit_memory 33 | 34 | velox-patch: 35 | cd velox && git checkout -f && git apply --whitespace=fix ../velox.patch && git apply --whitespace=fix ../velox_cast.patch 36 | -------------------------------------------------------------------------------- /cpp/doc/EnableAddressSanitizer.md: -------------------------------------------------------------------------------- 1 | # Enable AddressSanitizer 2 | 3 | ## Prepare 4 | 5 | - Set ```/proc/sys/vm/overcommit_memory``` as ```1```. 6 | - Find ```path/of/libasan.so``` by ```ldd libgluten_trino.so```. 7 | - Find ```path/of/libstdc++.so``` by ```ldd libgluten_trino.so```. 8 | - Set environment parameters to JVM: ```LD_PRELOAD=path/of/libasan.so:path/of/libstdc++.so;ASAN_OPTIONS=detect_leaks=1:handle_segv=0;LSAN_OPTIONS=suppressions=./trino-cpp/leak_suppress.txt``` -------------------------------------------------------------------------------- /cpp/leak_suppress.txt: -------------------------------------------------------------------------------- 1 | leak:libjvm.so 2 | leak:libjli.so 3 | leak:libz.so 4 | leak:mk_ascdate 5 | leak:Java_java_util_zip_Inflater_init 6 | -------------------------------------------------------------------------------- /cpp/scripts/install_deps_ubuntu.sh: -------------------------------------------------------------------------------- 1 | SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}") 2 | source $SCRIPTDIR/setup-velox-ubuntu.sh 3 | sudo apt install -y gperf uuid-dev libsodium-dev 4 | 5 | function install_proxygen { 6 | github_checkout facebook/proxygen "${FB_OS_VERSION}" 7 | cmake_install -DBUILD_TESTS=OFF 8 | } 9 | 10 | function install_antlr4 { 11 | wget https://www.antlr.org/download/antlr4-cpp-runtime-4.9.3-source.zip -O antlr4-cpp-runtime-4.9.3-source.zip 12 | mkdir antlr4-cpp-runtime-4.9.3-source 13 | pushd antlr4-cpp-runtime-4.9.3-source 14 | unzip ../antlr4-cpp-runtime-4.9.3-source.zip 15 | mkdir build && cd build 16 | cmake .. -DANTLR4_INSTALL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON 17 | make "-j${NPROC}" 18 | make install 19 | popd 20 | } 21 | 22 | function install_trino_deps { 23 | install_velox_deps 24 | run_and_time install_proxygen 25 | run_and_time install_antlr4 26 | } 27 | 28 | if [[ $# -ne 0 ]]; then 29 | for cmd in "$@"; do 30 | run_and_time "${cmd}" 31 | done 32 | else 33 | install_trino_deps 34 | fi -------------------------------------------------------------------------------- /cpp/src/PartitionOutputData.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace io::trino::bridge { 23 | 24 | class PartitionOutputData { 25 | public: 26 | explicit PartitionOutputData(); 27 | 28 | size_t getSequence() const { return sequence_; } 29 | 30 | bool getListenerRegistered() const { return listenerRegistered_; } 31 | 32 | void registerListener() { listenerRegistered_ = true; } 33 | 34 | void consumeListener() { listenerRegistered_ = false; } 35 | 36 | bool noMoreData() const { return noMore_; } 37 | 38 | size_t getOutputDataNum() const { return noMore_ ? data_.size() - 1 : data_.size(); } 39 | 40 | size_t getDataSize(size_t index) const; 41 | 42 | std::vector> popWithLock(size_t num); 43 | 44 | std::vector> pop(size_t num); 45 | 46 | void enqueueWithLock(size_t seq, std::vector>& data); 47 | 48 | void enqueue(size_t seq, std::vector>& data); 49 | 50 | template 51 | std::invoke_result_t withLock(F&& func, Args&&... args) const { 52 | std::lock_guard lg(lock_); 53 | return func(args...); 54 | } 55 | 56 | private: 57 | mutable std::recursive_mutex lock_; 58 | size_t sequence_; 59 | std::vector> data_; 60 | bool noMore_; 61 | bool listenerRegistered_; 62 | }; 63 | 64 | } // namespace io::trino::bridge 65 | -------------------------------------------------------------------------------- /cpp/src/functions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 | # use this file except in compliance with the License. You may obtain a copy of 3 | # the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 | # License for the specific language governing permissions and limitations under 11 | # the License. 12 | 13 | add_library(gluten_trino_functions OBJECT TpchPartitionFunction.cpp 14 | TrinoSumAggregate.cpp) 15 | target_link_libraries(gluten_trino_functions PUBLIC velox_core velox_exec 16 | velox_vector) 17 | 18 | if(GLUTEN_TRINO_BUILDING_TESTS) 19 | add_subdirectory(tests) 20 | endif() 21 | -------------------------------------------------------------------------------- /cpp/src/functions/TpchPartitionFunction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #pragma once 15 | 16 | #include "velox/core/PlanNode.h" 17 | 18 | using namespace facebook::velox; 19 | 20 | namespace io::trino::bridge { 21 | 22 | // This file is directly translated from Trino's 'io.trino.plugin.tpch.TpchBucketFunction' 23 | class TpchPartitionFunction : public core::PartitionFunction { 24 | public: 25 | explicit TpchPartitionFunction(int64_t rowsPerBucket, 26 | std::vector bucketToPartition); 27 | 28 | std::optional partition(const RowVector& input, 29 | std::vector& partitions); 30 | 31 | private: 32 | int64_t rowNumberFromOrderKey(int64_t orderKey); 33 | 34 | private: 35 | const int64_t _rowsPerBucket; 36 | const int32_t _bucketCount; 37 | std::vector _bucketToPartition; 38 | 39 | DecodedVector decodedVector; 40 | }; 41 | 42 | class TpchPartitionFunctionSpec : public core::PartitionFunctionSpec { 43 | public: 44 | explicit TpchPartitionFunctionSpec(int64_t rowsPerBucket, 45 | std::vector bucketToPartition); 46 | 47 | std::unique_ptr create(int /* numPartitions */) const override; 48 | 49 | std::string toString() const override; 50 | 51 | folly::dynamic serialize() const override; 52 | 53 | static core::PartitionFunctionSpecPtr deserialize(const folly::dynamic& obj, 54 | void* context); 55 | 56 | private: 57 | const int64_t _rowsPerBucket; 58 | std::vector _bucketToPartition; 59 | }; 60 | 61 | } // namespace io::trino::bridge -------------------------------------------------------------------------------- /cpp/src/functions/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 | # use this file except in compliance with the License. You may obtain a copy of 3 | # the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 | # License for the specific language governing permissions and limitations under 11 | # the License. 12 | 13 | add_executable(gluten_trino_function_tests TpchPartitionFunctionTest.cpp 14 | TrinoSumAggregateTest.cpp) 15 | add_test(gluten_trino_function_tests gluten_trino_function_tests) 16 | target_link_libraries(gluten_trino_function_tests gluten_trino_functions 17 | gtest_main) 18 | -------------------------------------------------------------------------------- /cpp/src/protocol/Base64Util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #pragma once 15 | #include "velox/vector/BaseVector.h" 16 | 17 | namespace io::trino::protocol { 18 | using namespace facebook; 19 | 20 | // Deserializes base64-encoded string created by 21 | // presto-common/src/main/java/com/facebook/presto/common/block/BlockEncodingManager.java 22 | // into vector. 23 | // TODO Refactor to avoid duplicating logic in PrestoSerializer. 24 | velox::VectorPtr readBlock(const velox::TypePtr& type, const std::string& base64Encoded, 25 | velox::memory::MemoryPool* pool); 26 | } // namespace io::trino::protocol 27 | -------------------------------------------------------------------------------- /cpp/src/protocol/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 | # use this file except in compliance with the License. You may obtain a copy of 3 | # the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 | # License for the specific language governing permissions and limitations under 11 | # the License. 12 | 13 | get_filename_component(TRINO_CPP_PLUGIN_DIR "${PROJECT_SOURCE_DIR}/../java" 14 | ABSOLUTE) 15 | if(DEFINED ENV{TRINO_HOME}) 16 | set(TRINO_ABSOLUTE_DIR $ENV{TRINO_HOME}) 17 | else() 18 | get_filename_component(TRINO_ABSOLUTE_DIR "$ENV{HOME}/trino" ABSOLUTE) 19 | endif() 20 | 21 | set(TRINO_PROTOCOL_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/trino_protocol.cpp) 22 | set(TRINO_PROTOCOL_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/trino_protocol.h) 23 | 24 | foreach(file ${TRINO_PROTOCOL_HEADER} ${TRINO_PROTOCOL_SOURCE}) 25 | if(EXISTS ${file}) 26 | message(STATUS "Deleting generated protocol file ${file}") 27 | file(REMOVE ${file}) 28 | endif() 29 | endforeach() 30 | 31 | add_custom_command( 32 | OUTPUT ${TRINO_PROTOCOL_SOURCE} ${TRINO_PROTOCOL_HEADER} 33 | COMMAND TRINO_HOME=${TRINO_ABSOLUTE_DIR} 34 | TRINO_CPP_PLUGIN_HOME=${TRINO_CPP_PLUGIN_DIR} make 35 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 36 | 37 | add_custom_target(internal_trino_protocol ALL DEPENDS ${TRINO_PROTOCOL_SOURCE} 38 | ${TRINO_PROTOCOL_HEADER}) 39 | 40 | add_library(trino_protocol OBJECT ${TRINO_PROTOCOL_SOURCE} DataSize.cpp 41 | Duration.cpp Base64Util.cpp) 42 | add_dependencies(trino_protocol internal_trino_protocol) 43 | 44 | target_link_libraries(trino_protocol PUBLIC ${RE2} ${FMT} Folly::folly 45 | velox_vector) 46 | -------------------------------------------------------------------------------- /cpp/src/protocol/DataSize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #pragma once 15 | #include 16 | #include 17 | 18 | namespace io::trino::protocol { 19 | 20 | enum class DataUnit { BYTE, KILOBYTE, MEGABYTE, GIGABYTE, TERABYTE, PETABYTE }; 21 | 22 | class DataSizeDataUnitUnsupported : public std::exception {}; 23 | class DataSizeStringInvalid : public std::exception {}; 24 | 25 | class DataSize { 26 | public: 27 | DataSize() = default; 28 | 29 | explicit DataSize(const std::string& string); 30 | 31 | DataSize(double value, DataUnit dataUnit) : value_(value), dataUnit_(dataUnit) {} 32 | 33 | double getValue() const { return value_; } 34 | 35 | DataUnit getDataUnit() const { return dataUnit_; } 36 | 37 | std::string toString() const; 38 | 39 | double getValue(DataUnit dataUnit) const { 40 | return value_ * (toBytesPerDataUnit(this->dataUnit_) / toBytesPerDataUnit(dataUnit)); 41 | } 42 | 43 | DataSize operator+=(const DataSize& other) { 44 | assert(this->getDataUnit() == other.getDataUnit()); 45 | value_ += other.getValue(); 46 | return *this; 47 | } 48 | 49 | static double toBytesPerDataUnit(DataUnit dataUnit); 50 | 51 | DataUnit valueOfDataUnit(const std::string& dataUnitString) const; 52 | 53 | std::string dataUnitToString(DataUnit dataUnit) const; 54 | 55 | private: 56 | double value_ = 0; 57 | DataUnit dataUnit_ = DataUnit::BYTE; 58 | }; 59 | 60 | } // namespace io::trino::protocol 61 | -------------------------------------------------------------------------------- /cpp/src/protocol/Makefile: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | .PHONY: trino_protocol trino_protocol-json trino_protocol-cpp 13 | 14 | OS := $(shell uname) 15 | ifeq ($(OS),Darwin) 16 | SEDCMD := "gsed" 17 | else 18 | SEDCMD := "sed" 19 | endif 20 | 21 | trino_protocol: trino_protocol-cpp 22 | 23 | trino_protocol-cpp: trino_protocol-json 24 | echo "// DO NOT EDIT : This file is generated by java-to-struct-json" > trino_protocol.cpp 25 | chevron -d trino_protocol.json trino_protocol-json-cpp.mustache >> trino_protocol.cpp 26 | echo "// DO NOT EDIT : This file is generated by java-to-struct-json" > trino_protocol.h 27 | chevron -d trino_protocol.json trino_protocol-json-hpp.mustache >> trino_protocol.h 28 | $(SEDCMD) -i 's/Gluten//gI' trino_protocol.* 29 | clang-format -style=file -i trino_protocol.h trino_protocol.cpp 30 | 31 | trino_protocol-json: 32 | ./java-to-struct-json.py special/*.java special/*.inc -j | jq . > trino_protocol.json 33 | 34 | trino_protocol.proto: trino_protocol-json 35 | pystache trino_protocol-protobuf.mustache trino_protocol.json > trino_protocol.proto 36 | -------------------------------------------------------------------------------- /cpp/src/protocol/license.header: -------------------------------------------------------------------------------- 1 | Copyright (c) Facebook, Inc. and its affiliates. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/AggregationNodeStep.java: -------------------------------------------------------------------------------- 1 | public enum AggregationNodeStep { 2 | PARTIAL, 3 | FINAL, 4 | INTERMEDIATE, 5 | SINGLE; 6 | } -------------------------------------------------------------------------------- /cpp/src/protocol/special/Block.cpp.inc: -------------------------------------------------------------------------------- 1 | namespace io::trino::protocol { 2 | 3 | void to_json(json& j, const Block& p) { j = p.data; } 4 | 5 | void from_json(const json& j, Block& p) { p.data = std::string(j); } 6 | } // namespace io::trino::protocol 7 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/Block.hpp.inc: -------------------------------------------------------------------------------- 1 | namespace io::trino::protocol { 2 | 3 | struct Block { 4 | std::string data; 5 | }; 6 | 7 | void to_json(json& j, const Block& p); 8 | 9 | void from_json(const json& j, Block& p); 10 | 11 | } // namespace io::trino::protocol 12 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/CatalogHandle.cpp.inc: -------------------------------------------------------------------------------- 1 | namespace io::trino::protocol { 2 | 3 | void to_json(nlohmann::json& j, const CatalogHandle& p) { j = p.catalogName; } 4 | 5 | void from_json(const nlohmann::json& j, CatalogHandle& p) { 6 | p.catalogName = std::string(j); 7 | } 8 | 9 | } // namespace io::trino::protocol -------------------------------------------------------------------------------- /cpp/src/protocol/special/CatalogHandle.hpp.inc: -------------------------------------------------------------------------------- 1 | namespace io::trino::protocol { 2 | 3 | struct CatalogHandle { 4 | std::string catalogName; 5 | }; 6 | 7 | void to_json(nlohmann::json& j, const CatalogHandle& p); 8 | void from_json(const nlohmann::json& j, CatalogHandle& p); 9 | 10 | } // namespace io::trino::protocol -------------------------------------------------------------------------------- /cpp/src/protocol/special/DataSize.cpp.inc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | namespace io::trino::protocol { 16 | 17 | void to_json(nlohmann::json& j, const DataSize& p) { j = p.toString(); } 18 | 19 | void from_json(const nlohmann::json& j, DataSize& p) { p = DataSize(std::string(j)); } 20 | 21 | std::ostream& operator<<(std::ostream& os, const DataSize& d) { 22 | return os << d.toString(); 23 | } 24 | 25 | } // namespace io::trino::protocol -------------------------------------------------------------------------------- /cpp/src/protocol/special/DataSize.hpp.inc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | namespace io::trino::protocol { 15 | 16 | std::ostream& operator<<(std::ostream& os, const DataSize& d); 17 | 18 | void to_json(nlohmann::json& j, const DataSize& p); 19 | void from_json(const nlohmann::json& j, DataSize& p); 20 | 21 | } // namespace io::trino::protocol 22 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/Duration.cpp.inc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | namespace io::trino::protocol { 16 | 17 | void to_json(json& j, const Duration& p) { j = p.toString(); } 18 | 19 | void from_json(const json& j, Duration& p) { p = Duration(std::string(j)); } 20 | 21 | std::ostream& operator<<(std::ostream& os, const Duration& d) { 22 | return os << d.toString(); 23 | } 24 | 25 | } // namespace io::trino::protocol 26 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/Duration.hpp.inc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | namespace io::trino::protocol { 16 | 17 | std::ostream& operator<<(std::ostream& os, const Duration& d); 18 | 19 | void to_json(json& j, const Duration& p); 20 | void from_json(const json& j, Duration& p); 21 | 22 | } // namespace io::trino::protocol 23 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/GlutenConnectorTransactionHandle.cpp.inc: -------------------------------------------------------------------------------- 1 | // dependency GlutenTpchTransactionHandle 2 | // dependency GlutenTupleDomain 3 | 4 | namespace io::trino::protocol { 5 | void to_json(json& j, const std::shared_ptr& p) { 6 | if (p == nullptr) { 7 | return; 8 | } 9 | String type = p->_type; 10 | 11 | /* 12 | if (type == "$remote") { 13 | j = *std::static_pointer_cast(p); 14 | return; 15 | } 16 | */ 17 | if (type == "system:io.trino.plugin.hive.protocol.HiveTransactionHandle") { 18 | j = *std::static_pointer_cast(p); 19 | return; 20 | } 21 | if (type == "system:io.trino.plugin.tpch.protocol.TpchTransactionHandle") { 22 | j = *std::static_pointer_cast(p); 23 | return; 24 | } 25 | 26 | throw TypeError(type + " no abstract type ConnectorTransactionHandle"); 27 | } 28 | 29 | void from_json(const json& j, std::shared_ptr& p) { 30 | String type; 31 | try { 32 | // TPC-H transactionHandle is an array ["tpch","INSTANCE"]. 33 | if (j.is_array()) { 34 | type = j[0]; 35 | } else { 36 | type = p->getSubclassKey(j); 37 | } 38 | } catch (json::parse_error& e) { 39 | throw ParseError(std::string(e.what()) + 40 | " ConnectorTransactionHandle ConnectorTransactionHandle"); 41 | } 42 | 43 | /* 44 | if (type == "$remote") { 45 | auto k = std::make_shared(); 46 | j.get_to(*k); 47 | p = k; 48 | return; 49 | } 50 | */ 51 | if (type == "system:io.trino.plugin.hive.protocol.HiveTransactionHandle") { 52 | auto k = std::make_shared(); 53 | j.get_to(*k); 54 | p = k; 55 | return; 56 | } 57 | if (type == "system:io.trino.plugin.tpch.protocol.TpchTransactionHandle") { 58 | auto k = std::make_shared(); 59 | j.get_to(*k); 60 | p = k; 61 | return; 62 | } 63 | 64 | throw TypeError(type + " no abstract type ConnectorTransactionHandle"); 65 | } 66 | } // namespace io::trino::protocol 67 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/GlutenTpchTransactionHandle.cpp.inc: -------------------------------------------------------------------------------- 1 | 2 | // TpchTransactionHandle is special since 3 | // the corresponding class in Java is an enum. 4 | 5 | namespace io::trino::protocol { 6 | 7 | void to_json(json& j, const GlutenTpchTransactionHandle& p) { 8 | j = json::array(); 9 | j.push_back(p._type); 10 | j.push_back(p.instance); 11 | } 12 | 13 | void from_json(const json& j, GlutenTpchTransactionHandle& p) { 14 | j[0].get_to(p._type); 15 | j[1].get_to(p.instance); 16 | } 17 | } // namespace io::trino::protocol 18 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/GlutenTpchTransactionHandle.hpp.inc: -------------------------------------------------------------------------------- 1 | 2 | // TpchTransactionHandle is special since 3 | // the corresponding class in Java is an enum. 4 | 5 | namespace io::trino::protocol { 6 | 7 | struct GlutenTpchTransactionHandle : public GlutenConnectorTransactionHandle { 8 | String instance = {}; 9 | }; 10 | 11 | void to_json(json& j, const GlutenTpchTransactionHandle& p); 12 | 13 | void from_json(const json& j, GlutenTpchTransactionHandle& p); 14 | 15 | } // namespace io::trino::protocol 16 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/GlutenVariableReferenceExpression.hpp.inc: -------------------------------------------------------------------------------- 1 | namespace io::trino::protocol { 2 | 3 | struct GlutenVariableReferenceExpression : GlutenRowExpression { 4 | String name; 5 | Type type; // dependency 6 | 7 | GlutenVariableReferenceExpression() noexcept; 8 | explicit GlutenVariableReferenceExpression(const String& str) { 9 | _type = "variable"; 10 | 11 | std::vector> parts; 12 | 13 | folly::split("<", str, parts); 14 | name = parts[0]; 15 | type = parts[1].substr(0, parts[1].length() - 1); 16 | } 17 | 18 | bool operator<(const GlutenVariableReferenceExpression& o) const { 19 | if (name == o.name) { 20 | return type < o.type; 21 | } 22 | 23 | return name < o.name; 24 | } 25 | }; 26 | 27 | void to_json(json& j, const GlutenVariableReferenceExpression& p); 28 | void from_json(const json& j, GlutenVariableReferenceExpression& p); 29 | std::string json_map_key(const GlutenVariableReferenceExpression& p); 30 | } // namespace io::trino::protocol 31 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/HivePartitioningHandle.java: -------------------------------------------------------------------------------- 1 | public class HivePartitioningHandle 2 | implements ConnectorPartitioningHandle 3 | { 4 | private final int bucketCount; 5 | private final List hiveTypes; 6 | private final OptionalInt maxCompatibleBucketCount; 7 | private final boolean usePartitionedBucketing; 8 | 9 | @JsonCreator 10 | public HivePartitioningHandle( 11 | @JsonProperty("bucketCount") int bucketCount, 12 | @JsonProperty("hiveBucketTypes") List hiveTypes, 13 | @JsonProperty("maxCompatibleBucketCount") OptionalInt maxCompatibleBucketCount, 14 | @JsonProperty("usePartitionedBucketing") boolean usePartitionedBucketing) 15 | { 16 | this.bucketCount = bucketCount; 17 | this.hiveTypes = requireNonNull(hiveTypes, "hiveTypes is null"); 18 | this.maxCompatibleBucketCount = maxCompatibleBucketCount; 19 | this.usePartitionedBucketing = usePartitionedBucketing; 20 | } 21 | 22 | @JsonProperty 23 | public int getBucketCount() 24 | { 25 | return bucketCount; 26 | } 27 | 28 | @JsonProperty 29 | public List getHiveTypes() 30 | { 31 | return hiveTypes; 32 | } 33 | 34 | @JsonProperty 35 | public OptionalInt getMaxCompatibleBucketCount() 36 | { 37 | return maxCompatibleBucketCount; 38 | } 39 | 40 | @JsonProperty 41 | public boolean isUsePartitionedBucketing() 42 | { 43 | return usePartitionedBucketing; 44 | } 45 | 46 | @Override 47 | public String toString() 48 | { 49 | ToStringHelper helper = toStringHelper(this) 50 | .add("buckets", bucketCount) 51 | .add("hiveTypes", hiveTypes); 52 | if (usePartitionedBucketing) { 53 | helper.add("usePartitionedBucketing", usePartitionedBucketing); 54 | } 55 | return helper.toString(); 56 | } 57 | 58 | @Override 59 | public boolean equals(Object o) 60 | { 61 | if (this == o) { 62 | return true; 63 | } 64 | if (o == null || getClass() != o.getClass()) { 65 | return false; 66 | } 67 | HivePartitioningHandle that = (HivePartitioningHandle) o; 68 | return bucketCount == that.bucketCount && 69 | usePartitionedBucketing == that.usePartitionedBucketing && 70 | Objects.equals(hiveTypes, that.hiveTypes); 71 | } 72 | 73 | @Override 74 | public int hashCode() 75 | { 76 | return Objects.hash(bucketCount, hiveTypes, usePartitionedBucketing); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/HostAddress.hpp.inc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | namespace io::trino::protocol { 16 | 17 | using HostAddress = std::string; 18 | 19 | } // namespace io::trino::protocol 20 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/JsonEncodedSubclass.cpp.inc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | // dependency KeyedSubclass 16 | 17 | namespace io::trino::protocol { 18 | 19 | std::string JsonEncodedSubclass::getSubclassKey(nlohmann::json j) { return j["@type"]; } 20 | 21 | } // namespace io::trino::protocol 22 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/OperatorInfo.cpp.inc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | namespace io::trino::protocol { 15 | void to_json(json& j, const OperatorInfo& p) {} 16 | void from_json(const json& j, OperatorInfo& p) {} 17 | } // namespace io::trino::protocol 18 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/OperatorInfo.hpp.inc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | namespace io::trino::protocol { 15 | struct OperatorInfo {}; 16 | void to_json(json& j, const OperatorInfo& p); 17 | void from_json(const json& j, OperatorInfo& p); 18 | } // namespace io::trino::protocol 19 | -------------------------------------------------------------------------------- /cpp/src/protocol/special/ValueEntry.hpp.inc: -------------------------------------------------------------------------------- 1 | namespace io::trino::protocol { 2 | 3 | class ValueEntry { 4 | public: 5 | Type type; 6 | std::shared_ptr block; 7 | }; 8 | 9 | void to_json(json& j, const ValueEntry& p); 10 | void from_json(const json& j, ValueEntry& p); 11 | 12 | } // namespace io::trino::protocol 13 | -------------------------------------------------------------------------------- /cpp/src/protocol/topological.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # The MIT License (MIT) 13 | # Copyright (c) 2014 Alexey Kachayev 14 | # 15 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 16 | # files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, 17 | # modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 18 | # is furnished to do so, subject to the following conditions: 19 | # 20 | # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 21 | # 22 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 23 | # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 24 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 25 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | from collections import deque 27 | 28 | GRAY, BLACK = 0, 1 29 | 30 | 31 | def topological(graph): 32 | order, enter, state = deque(), set(graph), {} 33 | 34 | def dfs(node): 35 | state[node] = GRAY 36 | for k in graph.get(node, ()): 37 | sk = state.get(k, None) 38 | if sk == GRAY: 39 | raise ValueError(f"cycle: {node} {k}") 40 | if sk == BLACK: 41 | continue 42 | enter.discard(k) 43 | dfs(k) 44 | order.appendleft(node) 45 | state[node] = BLACK 46 | 47 | while enter: 48 | dfs(enter.pop()) 49 | return order 50 | -------------------------------------------------------------------------------- /cpp/src/serialization/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 | # use this file except in compliance with the License. You may obtain a copy of 3 | # the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 | # License for the specific language governing permissions and limitations under 11 | # the License. 12 | 13 | set(SERIALIZATION_SOURCE TrinoSerializer.cpp TrinoBufferStream.cpp 14 | TrinoByteStream.cpp) 15 | 16 | add_library(gluten_trino_serialization OBJECT ${SERIALIZATION_SOURCE}) 17 | 18 | # link velox_vector_test_lib for VectorMaker 19 | target_link_libraries(gluten_trino_serialization PUBLIC ${VELOX_LIBS} ${FMT} 20 | Folly::folly ${RE2}) 21 | 22 | if(GLUTEN_TRINO_BUILDING_TESTS) 23 | add_subdirectory(tests) 24 | endif() 25 | -------------------------------------------------------------------------------- /cpp/src/serialization/TrinoBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | 19 | namespace io::trino::bridge { 20 | class MemoryManager { 21 | public: 22 | MemoryManager() {} 23 | char* allocate(size_t length) { return reinterpret_cast(std::malloc(length)); } 24 | void release(char* address) { std::free(address); } 25 | }; 26 | 27 | class TrinoBuffer { 28 | public: 29 | TrinoBuffer(std::shared_ptr memoryManager) 30 | : memoryManager_(memoryManager), address_(nullptr), length_(0) {} 31 | 32 | void init(size_t length) { 33 | address_ = memoryManager_->allocate(length); 34 | length_ = length; 35 | } 36 | char* getAddress() { return address_; } 37 | size_t getLength() { return length_; } 38 | 39 | void release() { memoryManager_->release(address_); } 40 | 41 | private: 42 | std::shared_ptr memoryManager_; 43 | char* address_; 44 | size_t length_; 45 | }; 46 | 47 | using TrinoBufferMap = std::unordered_map; 48 | } // namespace io::trino::bridge -------------------------------------------------------------------------------- /cpp/src/serialization/TrinoBufferStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #include "src/serialization/TrinoBufferStream.h" 15 | 16 | using namespace facebook::velox; 17 | 18 | namespace io::trino::bridge { 19 | 20 | std::streampos TrinoBufOutputStream::tellp() const { return out_->tellp(); } 21 | 22 | void TrinoBufOutputStream::seekp(std::streampos pos) { out_->seekp(pos); } 23 | 24 | TrinoBuffer TrinoBufOutputStream::getTrinoBuffer( 25 | std::shared_ptr memoryManager) { 26 | auto& ranges = out_->ranges(); 27 | TrinoBuffer trinoBuffer(memoryManager); 28 | for (auto& range : ranges) { 29 | trinoBuffer.init(range.position); 30 | std::memcpy(trinoBuffer.getAddress(), range.buffer, range.position); 31 | return trinoBuffer; 32 | } 33 | return trinoBuffer; 34 | } 35 | 36 | } // namespace io::trino::bridge 37 | -------------------------------------------------------------------------------- /cpp/src/serialization/TrinoBufferStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #pragma once 15 | 16 | #include "src/serialization/TrinoBuffer.h" 17 | #include "velox/common/memory/ByteStream.h" 18 | #include "velox/common/memory/StreamArena.h" 19 | #include "velox/type/Type.h" 20 | 21 | namespace io::trino::bridge { 22 | 23 | class TrinoBufOutputStream : public facebook::velox::OutputStream { 24 | public: 25 | explicit TrinoBufOutputStream( 26 | facebook::velox::memory::MemoryPool& pool, 27 | facebook::velox::OutputStreamListener* listener = nullptr, 28 | int32_t initialSize = facebook::velox::memory::AllocationTraits::kPageSize) 29 | : OutputStream(listener), 30 | arena_(std::make_shared(&pool)), 31 | out_(std::make_unique(arena_.get())) { 32 | out_->startWrite(initialSize); 33 | } 34 | 35 | void write(const char* s, std::streamsize count) override { 36 | out_->appendStringPiece(folly::StringPiece(s, count)); 37 | if (listener_) { 38 | listener_->onWrite(s, count); 39 | } 40 | } 41 | 42 | std::streampos tellp() const override; 43 | 44 | void seekp(std::streampos pos) override; 45 | 46 | TrinoBuffer getTrinoBuffer(std::shared_ptr memoryManager); 47 | /// 'releaseFn' is executed on iobuf destruction if not null. 48 | // std::unique_ptr getIOBuf( 49 | // const std::function& releaseFn = nullptr); 50 | 51 | private: 52 | std::shared_ptr arena_; 53 | std::unique_ptr out_; 54 | }; 55 | 56 | } // namespace io::trino::bridge 57 | -------------------------------------------------------------------------------- /cpp/src/serialization/TrinoByteStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #include "velox/common/memory/ByteStream.h" 15 | 16 | namespace io::trino::bridge { 17 | // class TrinoNullByteStream : public facebook::velox::memory::ByteStream { 18 | class TrinoNullByteStream { 19 | public: 20 | // For output. 21 | TrinoNullByteStream(facebook::velox::StreamArena* arena, bool isBits = false, 22 | bool isReverseBitOrder = false) 23 | : arena_(arena), isBits_(isBits), isReverseBitOrder_(isReverseBitOrder) {} 24 | void appendBool(bool value, int32_t count); 25 | void startWrite(int32_t initialSize) { extend(initialSize); } 26 | void flush(facebook::velox::OutputStream* stream); 27 | 28 | private: 29 | void extend(int32_t bytes = facebook::velox::memory::AllocationTraits::kPageSize); 30 | 31 | void updateEnd() { 32 | if (!ranges_.empty() && current_ == &ranges_.back() && 33 | current_->position > lastRangeEnd_) { 34 | lastRangeEnd_ = current_->position; 35 | } 36 | } 37 | 38 | facebook::velox::StreamArena* arena_; 39 | // Indicates that position in ranges_ is in bits, not bytes. 40 | const bool isBits_; 41 | const bool isReverseBitOrder_; 42 | 43 | // True if the bit order in ranges_ has been inverted. Presto requires reverse 44 | // bit order. 45 | bool isReversed_ = false; 46 | std::vector ranges_; 47 | // Pointer to the current element of 'ranges_'. 48 | facebook::velox::ByteRange* current_ = nullptr; 49 | int32_t lastRangeEnd_{0}; 50 | }; 51 | } // namespace io::trino::bridge 52 | -------------------------------------------------------------------------------- /cpp/src/serialization/TrinoSerializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #pragma once 15 | #include "velox/common/base/Crc.h" 16 | #include "velox/vector/VectorStream.h" 17 | 18 | namespace io::trino::bridge { 19 | 20 | class TrinoVectorSerde : public facebook::velox::VectorSerde { 21 | public: 22 | TrinoVectorSerde() {} 23 | struct TrinoOptions : VectorSerde::Options { 24 | explicit TrinoOptions(bool useLosslessTimestamp) 25 | : useLosslessTimestamp(useLosslessTimestamp) {} 26 | // Currently presto only supports millisecond precision and the serializer 27 | // converts velox native timestamp to that resulting in loss of precision. 28 | // This option allows it to serialize with nanosecond precision and is 29 | // currently used for spilling. Is false by default. 30 | bool useLosslessTimestamp{false}; 31 | }; 32 | 33 | void estimateSerializedSize( 34 | facebook::velox::VectorPtr vector, 35 | const folly::Range& ranges, 36 | facebook::velox::vector_size_t** sizes) override; 37 | 38 | std::unique_ptr createSerializer( 39 | std::shared_ptr type, int32_t numRows, 40 | facebook::velox::StreamArena* streamArena, const Options* options) override; 41 | 42 | void deserialize(facebook::velox::ByteStream* source, 43 | facebook::velox::memory::MemoryPool* pool, 44 | facebook::velox::RowTypePtr type, 45 | facebook::velox::RowVectorPtr* result, 46 | const Options* options = nullptr) override; 47 | static void registerVectorSerde(); 48 | }; 49 | 50 | class TrinoOutputStreamListener : public facebook::velox::OutputStreamListener {}; 51 | } // namespace io::trino::bridge 52 | -------------------------------------------------------------------------------- /cpp/src/serialization/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 | # use this file except in compliance with the License. You may obtain a copy of 3 | # the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 | # License for the specific language governing permissions and limitations under 11 | # the License. 12 | 13 | set(TEST_LIBS gluten_trino gtest) 14 | 15 | add_executable(SerdeTest SerdeTest.cpp) 16 | target_link_libraries(SerdeTest ${TEST_LIBS}) 17 | add_test(SerdeTest ${EXECUTABLE_OUTPUT_PATH}/SerdeTest ${TEST_ARGS}) 18 | -------------------------------------------------------------------------------- /cpp/src/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | add_executable(gluten_trino_tests NativeConfigsTest.cpp 14 | PartitionOutputDataTest.cpp) 15 | add_test(gluten_trino_tests gluten_trino_tests) 16 | target_link_libraries(gluten_trino_tests gluten_trino gtest_main) 17 | -------------------------------------------------------------------------------- /cpp/src/tests/PartitionOutputDataTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include "src/PartitionOutputData.h" 19 | 20 | class PartitionOutputDataTest : public ::testing::Test {}; 21 | 22 | TEST(PartitionOutputDataTest, basic) { 23 | io::trino::bridge::PartitionOutputData output; 24 | for (int i = 0; i < 10; ++i) { 25 | std::vector> data; 26 | data.emplace_back(std::make_unique()); 27 | 28 | ASSERT_EQ(output.getSequence(), i); 29 | output.enqueue(i, data); 30 | ASSERT_EQ(output.getSequence(), i + 1); 31 | ASSERT_EQ(output.getDataSize(i), 0); 32 | } 33 | 34 | ASSERT_EQ(output.getSequence(), 10); 35 | ASSERT_EQ(output.getOutputDataNum(), 10); 36 | 37 | auto result = output.pop(10); 38 | ASSERT_EQ(result.size(), 10); 39 | for (auto& buf : result) { 40 | ASSERT_EQ(buf->computeChainDataLength(), 0); 41 | } 42 | ASSERT_EQ(output.getOutputDataNum(), 0); 43 | 44 | std::vector> poison; 45 | poison.emplace_back(nullptr); 46 | output.enqueue(10, poison); 47 | ASSERT_EQ(output.getOutputDataNum(), 0); 48 | } 49 | -------------------------------------------------------------------------------- /cpp/src/types/.gitattributes: -------------------------------------------------------------------------------- 1 | antlr/* -merge 2 | antlr/* linguist-generated=true 3 | -------------------------------------------------------------------------------- /cpp/src/types/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 | # use this file except in compliance with the License. You may obtain a copy of 3 | # the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 | # License for the specific language governing permissions and limitations under 11 | # the License. 12 | 13 | add_library( 14 | presto_type_converter OBJECT 15 | PrestoToVeloxQueryPlan.cpp PrestoToVeloxExpr.cpp 16 | TypeSignatureTypeConverter.cpp antlr/TypeSignatureParser.cpp 17 | antlr/TypeSignatureLexer.cpp PrestoToVeloxSplit.cpp) 18 | 19 | add_dependencies(presto_type_converter velox_type velox_dwio_dwrf_proto 20 | trino_protocol) 21 | 22 | target_link_libraries( 23 | presto_type_converter PUBLIC antlr4_static velox_tpch_connector 24 | velox_tpch_gen velox_type) 25 | 26 | if(GLUTEN_TRINO_BUILDING_TESTS) 27 | add_subdirectory(tests) 28 | endif() 29 | -------------------------------------------------------------------------------- /cpp/src/types/Makefile: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | .PHONY: TypeSignature parser format-fix header-fix 13 | 14 | TypeSignature: parser format-fix header-fix 15 | 16 | parser: 17 | antlr -Dlanguage=Cpp -package facebook::presto::type -visitor -no-listener -o antlr TypeSignature.g4 18 | rm -rf .antlr 19 | find antlr | ../../../velox/scripts/license-header.py --header ../../../license.header -i - 20 | find antlr | ../../../velox/scripts/license-header.py --header ../../../license.header -vk - 21 | 22 | format-fix: 23 | ../../../velox/scripts/check.py format tree antlr --fix 24 | ../../../velox/scripts/check.py format tree antlr 25 | 26 | header-fix: 27 | ../../../velox/scripts/check.py format tree antlr --fix 28 | ../../../velox/scripts/check.py format tree antlr 29 | -------------------------------------------------------------------------------- /cpp/src/types/ParseTypeSignature.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #pragma once 15 | #include "velox/type/Type.h" 16 | 17 | namespace io::trino { 18 | facebook::velox::TypePtr parseTypeSignature(const std::string& signature); 19 | } // namespace io::trino 20 | -------------------------------------------------------------------------------- /cpp/src/types/PrestoToVeloxSplit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #pragma once 15 | 16 | #include "src/protocol/trino_protocol.h" 17 | #include "velox/exec/Split.h" 18 | 19 | namespace io::trino { 20 | 21 | // Creates and returns exec::Split (with connector::ConnectorSplit inside) based 22 | // on the given protocol split. 23 | facebook::velox::exec::Split toVeloxSplit(const protocol::ScheduledSplit& scheduledSplit); 24 | 25 | } // namespace io::trino 26 | -------------------------------------------------------------------------------- /cpp/src/types/README.md: -------------------------------------------------------------------------------- 1 | presto_cpp uses antlr4 to parse types. 2 | Details on how to create a lexer and parser using antlr4 are available here: 3 | https://github.com/antlr/antlr4/blob/master/doc/cpp-target.md 4 | 5 | **TypeSignature.g4** file specifies the grammar. Any new rules must be added to this file. 6 | presto_cpp requires the antlr4 **visitor** and does not need the antlr4 **listener**. 7 | antlr files are generated using the following command: 8 | 9 | antlr4 -Dlanguage=Cpp -no-listener -visitor TypeSignature.g4 -o antlr 10 | 11 | The following files are generated inside the antlr directory: 12 | + TypeSignature.interp 13 | + TypeSignature.tokens 14 | + TypeSignatureBaseVisitor.cpp 15 | + TypeSignatureBaseVisitor.h 16 | + TypeSignatureLexer.cpp 17 | + TypeSignatureLexer.h 18 | + TypeSignatureLexer.interp 19 | + TypeSignatureLexer.tokens 20 | + TypeSignatureParser.cpp 21 | + TypeSignatureParser.h 22 | + TypeSignatureVisitor.cpp 23 | + TypeSignatureVisitor.h 24 | 25 | The generated .cpp and .h files need to be modified as described below: 26 | 1) Invoke 'make header-fix' to include the copyright header in the generated files. 27 | 2) Encapsulate code in the namespace facebook::presto::type. 28 | -------------------------------------------------------------------------------- /cpp/src/types/TrinoTaskId.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #pragma once 15 | #include 16 | #include 17 | 18 | namespace io::trino { 19 | class TrinoTaskId { 20 | public: 21 | explicit TrinoTaskId(const std::string& taskId) : fullId_(taskId) { 22 | int start = 0; 23 | auto pos = nextDot(taskId, start); 24 | queryId_ = taskId.substr(0, pos); 25 | 26 | start = pos + 1; 27 | pos = nextDot(taskId, start); 28 | stageId_ = parseInt(taskId, start, pos); 29 | 30 | start = pos + 1; 31 | pos = nextDot(taskId, start); 32 | stageExecutionId_ = parseInt(taskId, start, pos); 33 | 34 | start = pos + 1; 35 | id_ = parseInt(taskId, start, taskId.length()); 36 | } 37 | 38 | const std::string& fullId() const { return fullId_; } 39 | 40 | const std::string& queryId() const { return queryId_; } 41 | 42 | int32_t stageId() const { return stageId_; } 43 | 44 | int32_t stageExecutionId() const { return stageExecutionId_; } 45 | 46 | int32_t id() const { return id_; } 47 | 48 | private: 49 | int nextDot(const std::string& taskId, int start) { 50 | auto pos = taskId.find(".", start); 51 | if (pos == std::string::npos) { 52 | throw std::invalid_argument("Malformed task ID: " + taskId); 53 | } 54 | return pos; 55 | } 56 | 57 | int parseInt(const std::string& taskId, int start, int end) { 58 | return folly::to(taskId.substr(start, end - start)); 59 | } 60 | 61 | const std::string fullId_; 62 | std::string queryId_; 63 | int32_t stageId_; 64 | int32_t stageExecutionId_; 65 | int32_t id_; 66 | }; 67 | } // namespace io::trino 68 | -------------------------------------------------------------------------------- /cpp/src/types/TypeSignatureTypeConverter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | #pragma once 16 | 17 | #include "velox/type/Type.h" 18 | #include "src/types/antlr/TypeSignatureBaseVisitor.h" 19 | 20 | namespace io { 21 | namespace trino { 22 | using namespace type; 23 | using namespace facebook; 24 | 25 | class TypeSignatureTypeConverter : TypeSignatureBaseVisitor { 26 | virtual antlrcpp::Any visitStart(TypeSignatureParser::StartContext* ctx) override; 27 | virtual antlrcpp::Any visitNamed_type( 28 | TypeSignatureParser::Named_typeContext* ctx) override; 29 | virtual antlrcpp::Any visitType_spec( 30 | TypeSignatureParser::Type_specContext* ctx) override; 31 | virtual antlrcpp::Any visitType(TypeSignatureParser::TypeContext* ctx) override; 32 | virtual antlrcpp::Any visitSimple_type( 33 | TypeSignatureParser::Simple_typeContext* ctx) override; 34 | virtual antlrcpp::Any visitDecimal_type( 35 | TypeSignatureParser::Decimal_typeContext* ctx) override; 36 | virtual antlrcpp::Any visitVariable_type( 37 | TypeSignatureParser::Variable_typeContext* ctx) override; 38 | virtual antlrcpp::Any visitType_list( 39 | TypeSignatureParser::Type_listContext* ctx) override; 40 | virtual antlrcpp::Any visitRow_type(TypeSignatureParser::Row_typeContext* ctx) override; 41 | virtual antlrcpp::Any visitMap_type(TypeSignatureParser::Map_typeContext* ctx) override; 42 | virtual antlrcpp::Any visitArray_type( 43 | TypeSignatureParser::Array_typeContext* ctx) override; 44 | virtual antlrcpp::Any visitIdentifier( 45 | TypeSignatureParser::IdentifierContext* ctx) override; 46 | 47 | public: 48 | static std::shared_ptr parse(const std::string& text); 49 | }; 50 | 51 | struct NamedType { 52 | std::string name; 53 | velox::TypePtr type; 54 | }; 55 | 56 | velox::TypePtr typeFromString(const std::string& typeName); 57 | velox::TypePtr rowFromNamedTypes(const std::vector& named); 58 | velox::TypePtr mapFromKeyValueType(velox::TypePtr keyType, velox::TypePtr valueType); 59 | velox::TypePtr arrayFromType(velox::TypePtr valueType); 60 | 61 | } // namespace trino 62 | } // namespace io 63 | -------------------------------------------------------------------------------- /cpp/src/types/antlr/TypeSignature.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | TYPE_WITH_SPACES=4 5 | WORD=5 6 | QUOTED_ID=6 7 | NUMBER=7 8 | WHITESPACE=8 9 | '('=1 10 | ')'=2 11 | ','=3 12 | -------------------------------------------------------------------------------- /cpp/src/types/antlr/TypeSignatureBaseVisitor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | #include 16 | #include "src/types/TypeSignatureTypeConverter.h" 17 | 18 | // Generated from TypeSignature.g4 by ANTLR 4.9.3 19 | 20 | #include "TypeSignatureBaseVisitor.h" 21 | 22 | using namespace io::trino::type; 23 | -------------------------------------------------------------------------------- /cpp/src/types/antlr/TypeSignatureLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | TYPE_WITH_SPACES=4 5 | WORD=5 6 | QUOTED_ID=6 7 | NUMBER=7 8 | WHITESPACE=8 9 | '('=1 10 | ')'=2 11 | ','=3 12 | -------------------------------------------------------------------------------- /cpp/src/types/antlr/TypeSignatureVisitor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | #include 16 | #include "src/types/TypeSignatureTypeConverter.h" 17 | 18 | // Generated from TypeSignature.g4 by ANTLR 4.9.3 19 | 20 | #include "TypeSignatureVisitor.h" 21 | 22 | using namespace io::trino::type; 23 | -------------------------------------------------------------------------------- /cpp/src/types/antlr/TypeSignatureVisitor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | #include 16 | #include "src/types/TypeSignatureTypeConverter.h" 17 | 18 | // Generated from TypeSignature.g4 by ANTLR 4.9.3 19 | 20 | #pragma once 21 | 22 | #include "TypeSignatureParser.h" 23 | #include "antlr4-runtime.h" 24 | 25 | namespace io::trino::type { 26 | 27 | /** 28 | * This class defines an abstract visitor for a parse tree 29 | * produced by TypeSignatureParser. 30 | */ 31 | class TypeSignatureVisitor : public antlr4::tree::AbstractParseTreeVisitor { 32 | public: 33 | /** 34 | * Visit parse trees produced by TypeSignatureParser. 35 | */ 36 | virtual antlrcpp::Any visitStart(TypeSignatureParser::StartContext* context) = 0; 37 | 38 | virtual antlrcpp::Any visitType_spec( 39 | TypeSignatureParser::Type_specContext* context) = 0; 40 | 41 | virtual antlrcpp::Any visitNamed_type( 42 | TypeSignatureParser::Named_typeContext* context) = 0; 43 | 44 | virtual antlrcpp::Any visitType(TypeSignatureParser::TypeContext* context) = 0; 45 | 46 | virtual antlrcpp::Any visitSimple_type( 47 | TypeSignatureParser::Simple_typeContext* context) = 0; 48 | 49 | virtual antlrcpp::Any visitVariable_type( 50 | TypeSignatureParser::Variable_typeContext* context) = 0; 51 | 52 | virtual antlrcpp::Any visitDecimal_type( 53 | TypeSignatureParser::Decimal_typeContext* context) = 0; 54 | 55 | virtual antlrcpp::Any visitType_list( 56 | TypeSignatureParser::Type_listContext* context) = 0; 57 | 58 | virtual antlrcpp::Any visitRow_type(TypeSignatureParser::Row_typeContext* context) = 0; 59 | 60 | virtual antlrcpp::Any visitMap_type(TypeSignatureParser::Map_typeContext* context) = 0; 61 | 62 | virtual antlrcpp::Any visitArray_type( 63 | TypeSignatureParser::Array_typeContext* context) = 0; 64 | 65 | virtual antlrcpp::Any visitIdentifier( 66 | TypeSignatureParser::IdentifierContext* context) = 0; 67 | }; 68 | 69 | } // namespace io::trino::type 70 | -------------------------------------------------------------------------------- /cpp/src/types/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 | # use this file except in compliance with the License. You may obtain a copy of 3 | # the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 | # License for the specific language governing permissions and limitations under 11 | # the License. 12 | 13 | add_executable( 14 | type_convertor_test 15 | TypeSignatureConverterTest.cpp RowExpressionConverterTest.cpp 16 | VeloxSplitConverterTest.cpp PlanNodeConverterTest.cpp ValuesPipeTest.cpp) 17 | 18 | add_test( 19 | NAME type_convertor_test 20 | COMMAND type_convertor_test 21 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 22 | 23 | add_dependencies(type_convertor_test gluten_trino) 24 | 25 | target_link_libraries(type_convertor_test gtest_main gluten_trino) 26 | -------------------------------------------------------------------------------- /cpp/src/utils/HttpConstants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #pragma once 15 | namespace io::trino::bridge::http { 16 | 17 | const uint16_t kHttpOk = 200; 18 | const uint16_t kHttpAccepted = 202; 19 | const uint16_t kHttpNoContent = 204; 20 | const uint16_t kHttpNotFound = 404; 21 | const uint16_t kHttpInternalServerError = 500; 22 | 23 | const char kMimeTypeApplicationJson[] = "application/json"; 24 | const char kMimeTypeApplicationThrift[] = "application/x-thrift+binary"; 25 | } // namespace io::trino::bridge::http 26 | -------------------------------------------------------------------------------- /cpp/src/utils/JniUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "src/types/TrinoTaskId.h" 8 | 9 | namespace io::trino::bridge { 10 | 11 | class JniUtils { 12 | public: 13 | static std::string jstringToString(JNIEnv* jniEnv, jstring jstr); 14 | static void throwJavaRuntimeException(JNIEnv* jniEnv, const std::string& errorMessage); 15 | 16 | static void logDebug(JNIEnv* jniEnv, const char* file, int32_t line, 17 | const std::string& logMessage); 18 | static void logInfo(JNIEnv* jniEnv, const char* file, int32_t line, 19 | const std::string& logMessage); 20 | static void logWarning(JNIEnv* jniEnv, const char* file, int32_t line, 21 | const std::string& logMessage); 22 | static void logError(JNIEnv* jniEnv, const char* file, int32_t line, 23 | const std::string& logMessage); 24 | 25 | static jobject createJavaRuntimeException(JNIEnv* jniEnv, 26 | const std::string& errorMessage); 27 | 28 | static JNIEnv* getJNIEnv(); 29 | }; 30 | 31 | class Unsafe { 32 | public: 33 | static Unsafe& instance(); 34 | 35 | void initialize(JNIEnv* env); 36 | 37 | template 38 | int32_t arraySliceSize(int32_t length) const; 39 | 40 | private: 41 | explicit Unsafe() = default; 42 | 43 | static int32_t multiplyExact(int x, int y); 44 | static int32_t getUnsafeArrayIndexScale(JNIEnv* env, jclass unsafeClass, 45 | const std::string& name); 46 | 47 | int32_t arrayIntIndexScale = 4; 48 | int32_t arrayLongIndexScale = 8; 49 | int32_t arrayBooleanIndexScale = 1; 50 | }; 51 | 52 | class NativeSqlTaskExecutionManager { 53 | public: 54 | explicit NativeSqlTaskExecutionManager(jobject managerObj); 55 | 56 | void requestFetchNativeOutput(const TrinoTaskId& taskId, int partitionId); 57 | 58 | void requestUpdateNativeTaskStatus(const TrinoTaskId& taskId); 59 | 60 | private: 61 | jmethodID getMemberFunction(JNIEnv* env, const char* fname, const char* signture); 62 | 63 | private: 64 | jobject javaObj_; 65 | }; 66 | 67 | using NativeSqlTaskExecutionManagerPtr = std::shared_ptr; 68 | } // namespace io::trino::bridge 69 | -------------------------------------------------------------------------------- /cpp/src/utils/ThreadUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "src/utils/ThreadUtils.h" 2 | 3 | namespace io::trino::bridge { 4 | 5 | std::shared_ptr getDriverCPUExecutor( 6 | size_t threadNum, const std::string& name) { 7 | static auto executor = std::make_shared( 8 | threadNum, std::make_shared(name)); 9 | return executor; 10 | } 11 | 12 | std::shared_ptr getSpillExecutor(size_t threadNum, 13 | const std::string& name) { 14 | static auto executor = std::make_shared( 15 | threadNum, std::make_shared(name)); 16 | return executor; 17 | } 18 | 19 | std::shared_ptr getExchangeIOCPUExecutor( 20 | size_t threadNum, const std::string& name) { 21 | static auto executor = std::make_shared( 22 | threadNum, std::make_shared(name)); 23 | return executor; 24 | } 25 | 26 | std::shared_ptr getConnectorIOExecutor( 27 | size_t threadNum, const std::string& name) { 28 | static auto executor = std::make_shared( 29 | threadNum, std::make_shared(name)); 30 | return executor; 31 | } 32 | 33 | } // namespace io::trino::bridge -------------------------------------------------------------------------------- /cpp/src/utils/ThreadUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #pragma once 15 | 16 | #include 17 | #include 18 | 19 | #include "folly/executors/CPUThreadPoolExecutor.h" 20 | #include "folly/executors/IOThreadPoolExecutor.h" 21 | 22 | namespace io::trino::bridge { 23 | 24 | std::shared_ptr getDriverCPUExecutor( 25 | size_t threadNum = 8, const std::string& name = "Driver"); 26 | 27 | std::shared_ptr getExchangeIOCPUExecutor( 28 | size_t threadNum = 8, const std::string& name = "ExchangeIO"); 29 | 30 | std::shared_ptr getSpillExecutor( 31 | size_t threadNum = 8, const std::string& name = "SpillIO"); 32 | 33 | std::shared_ptr getConnectorIOExecutor( 34 | size_t threadNum = 8, const std::string& name = "ConnectorIO"); 35 | } // namespace io::trino::bridge 36 | -------------------------------------------------------------------------------- /cpp/velox.patch: -------------------------------------------------------------------------------- 1 | diff --git a/velox/connectors/tpch/TpchConnector.cpp b/velox/connectors/tpch/TpchConnector.cpp 2 | index 1bf4eac4..e365561b 100644 3 | --- a/velox/connectors/tpch/TpchConnector.cpp 4 | +++ b/velox/connectors/tpch/TpchConnector.cpp 5 | @@ -129,8 +129,12 @@ void TpchDataSource::addSplit(std::shared_ptr split) { 6 | currentSplit_ = std::dynamic_pointer_cast(split); 7 | VELOX_CHECK(currentSplit_, "Wrong type of split for TpchDataSource."); 8 | 9 | + size_t tpchTableRowCount = tpchTable_ == tpch::Table::TBL_LINEITEM 10 | + ? getRowCount(tpch::Table::TBL_ORDERS, scaleFactor_) 11 | + : tpchTableRowCount_; 12 | + 13 | size_t partSize = 14 | - std::ceil((double)tpchTableRowCount_ / (double)currentSplit_->totalParts); 15 | + std::ceil((double)tpchTableRowCount / (double)currentSplit_->totalParts); 16 | 17 | splitOffset_ = partSize * currentSplit_->partNumber; 18 | splitEnd_ = splitOffset_ + partSize; 19 | diff --git a/velox/tpch/gen/TpchGen.cpp b/velox/tpch/gen/TpchGen.cpp 20 | index 4ccd3ee2..3a972bff 100644 21 | --- a/velox/tpch/gen/TpchGen.cpp 22 | +++ b/velox/tpch/gen/TpchGen.cpp 23 | @@ -456,7 +456,7 @@ RowVectorPtr genTpchLineItem( 24 | 25 | lineNumberVector->set(lineItemCount + l, line.lcnt); 26 | 27 | - quantityVector->set(lineItemCount + l, decimalToDouble(line.quantity)); 28 | + quantityVector->set(lineItemCount + l, 100 * decimalToDouble(line.quantity)); 29 | extendedPriceVector->set(lineItemCount + l, decimalToDouble(line.eprice)); 30 | discountVector->set(lineItemCount + l, decimalToDouble(line.discount)); 31 | taxVector->set(lineItemCount + l, decimalToDouble(line.tax)); 32 | -------------------------------------------------------------------------------- /docs/gluten-trino-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oap-project/Gluten-Trino/e2c8171559d5268b8368776f9f93919006872419/docs/gluten-trino-arch.png -------------------------------------------------------------------------------- /java/.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | io.takari.aether 5 | takari-local-repository 6 | 0.11.3 7 | 8 | 9 | -------------------------------------------------------------------------------- /java/.mvn/jvm.config: -------------------------------------------------------------------------------- 1 | -Xmx8192m 2 | --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED 3 | --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED 4 | --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED 5 | --add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED 6 | --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED 7 | --add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED 8 | --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED 9 | --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED 10 | --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED 11 | --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED 12 | -------------------------------------------------------------------------------- /java/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oap-project/Gluten-Trino/e2c8171559d5268b8368776f9f93919006872419/java/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /java/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/execution/TaskExecution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.execution; 15 | 16 | import io.trino.operator.TaskContext; 17 | import io.trino.sql.planner.plan.PlanNodeId; 18 | 19 | import java.util.List; 20 | import java.util.Set; 21 | 22 | public interface TaskExecution 23 | { 24 | void start(); 25 | 26 | void addSplitAssignments(List splitAssignments); 27 | 28 | Set getNoMoreSplits(); 29 | 30 | TaskContext getTaskContext(); 31 | } 32 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/jni/NativeLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.jni; 15 | 16 | import io.airlift.log.Logger; 17 | 18 | // This class used by Trino Native library for writing log in Trino format. 19 | @SuppressWarnings("unused") 20 | public class NativeLogger 21 | { 22 | private static final Logger log = Logger.get(NativeLogger.class); 23 | 24 | private NativeLogger() 25 | { 26 | } 27 | 28 | public static void logDebug(String message) 29 | { 30 | log.debug(message); 31 | } 32 | 33 | public static void logInfo(String message) 34 | { 35 | log.info(message); 36 | } 37 | 38 | public static void logWarning(String message) 39 | { 40 | log.warn(message); 41 | } 42 | 43 | public static void logError(String message) 44 | { 45 | log.error(message); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/hive/HiveTransactionHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.plugin.hive; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.plugin.hive.protocol.GlutenHiveTransactionHandle; 19 | import io.trino.spi.connector.ConnectorTransactionHandle; 20 | 21 | import java.util.Objects; 22 | import java.util.UUID; 23 | 24 | import static java.util.Objects.requireNonNull; 25 | 26 | public class HiveTransactionHandle 27 | implements ConnectorTransactionHandle 28 | { 29 | private final boolean autoCommit; 30 | private final UUID uuid; 31 | 32 | public HiveTransactionHandle(boolean autoCommit) 33 | { 34 | this(autoCommit, UUID.randomUUID()); 35 | } 36 | 37 | @JsonCreator 38 | public HiveTransactionHandle(@JsonProperty("autoCommit") boolean autoCommit, @JsonProperty("uuid") UUID uuid) 39 | { 40 | this.autoCommit = autoCommit; 41 | this.uuid = requireNonNull(uuid, "uuid is null"); 42 | } 43 | 44 | @JsonProperty 45 | public boolean isAutoCommit() 46 | { 47 | return autoCommit; 48 | } 49 | 50 | @JsonProperty 51 | public UUID getUuid() 52 | { 53 | return uuid; 54 | } 55 | 56 | @Override 57 | public boolean equals(Object o) 58 | { 59 | if (this == o) { 60 | return true; 61 | } 62 | if (o == null || getClass() != o.getClass()) { 63 | return false; 64 | } 65 | HiveTransactionHandle that = (HiveTransactionHandle) o; 66 | return autoCommit == that.autoCommit && Objects.equals(uuid, that.uuid); 67 | } 68 | 69 | @Override 70 | public int hashCode() 71 | { 72 | return Objects.hash(autoCommit, uuid); 73 | } 74 | 75 | @Override 76 | public String toString() 77 | { 78 | return uuid.toString(); 79 | } 80 | 81 | @Override 82 | public GlutenHiveTransactionHandle getProtocol() 83 | { 84 | return new GlutenHiveTransactionHandle(uuid); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/hive/protocol/GlutenBucketFunctionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.plugin.hive.protocol; 16 | 17 | public enum GlutenBucketFunctionType 18 | { 19 | HIVE_COMPATIBLE, 20 | PRESTO_NATIVE 21 | } 22 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/hive/protocol/GlutenCacheQuotaRequirement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.plugin.hive.protocol; 16 | 17 | import com.fasterxml.jackson.annotation.JsonCreator; 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | import io.airlift.units.DataSize; 20 | 21 | import java.util.Objects; 22 | import java.util.Optional; 23 | 24 | import static com.google.common.base.MoreObjects.toStringHelper; 25 | import static java.util.Objects.requireNonNull; 26 | 27 | public class GlutenCacheQuotaRequirement 28 | { 29 | private final GlutenCacheQuotaScope cacheQuotaScope; 30 | private final Optional quota; 31 | 32 | @JsonCreator 33 | public GlutenCacheQuotaRequirement( 34 | @JsonProperty("cacheQuotaScope") GlutenCacheQuotaScope cacheQuotaScope, 35 | @JsonProperty("quota") Optional quota) 36 | { 37 | this.cacheQuotaScope = requireNonNull(cacheQuotaScope, "cacheQuotaScope"); 38 | this.quota = quota; 39 | } 40 | 41 | @JsonProperty 42 | public GlutenCacheQuotaScope getCacheQuotaScope() 43 | { 44 | return cacheQuotaScope; 45 | } 46 | 47 | @JsonProperty 48 | public Optional getQuota() 49 | { 50 | return quota; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object o) 55 | { 56 | if (this == o) { 57 | return true; 58 | } 59 | if (o == null || getClass() != o.getClass()) { 60 | return false; 61 | } 62 | 63 | GlutenCacheQuotaRequirement that = (GlutenCacheQuotaRequirement) o; 64 | return Objects.equals(cacheQuotaScope, that.cacheQuotaScope) && Objects.equals(quota, that.quota); 65 | } 66 | 67 | @Override 68 | public int hashCode() 69 | { 70 | return Objects.hash(cacheQuotaScope, quota); 71 | } 72 | 73 | @Override 74 | public String toString() 75 | { 76 | return toStringHelper(this) 77 | .add("cacheQuotaScope", cacheQuotaScope) 78 | .add("quota", quota) 79 | .toString(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/hive/protocol/GlutenCacheQuotaScope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.plugin.hive.protocol; 16 | 17 | public enum GlutenCacheQuotaScope 18 | { 19 | GLOBAL, SCHEMA, TABLE, PARTITION 20 | } 21 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/hive/protocol/GlutenDwrfEncryptionMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.plugin.hive.protocol; 16 | 17 | import com.fasterxml.jackson.annotation.JsonCreator; 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | import com.google.common.collect.ImmutableMap; 20 | 21 | import java.util.Map; 22 | 23 | import static java.util.Objects.requireNonNull; 24 | 25 | public class GlutenDwrfEncryptionMetadata 26 | implements GlutenEncryptionMetadata 27 | { 28 | private final Map fieldToKeyData; 29 | private final Map extraMetadata; 30 | private final String encryptionAlgorithm; 31 | private final String encryptionProvider; 32 | 33 | @JsonCreator 34 | public GlutenDwrfEncryptionMetadata( 35 | @JsonProperty Map fieldToKeyData, 36 | @JsonProperty Map extraMetadata, 37 | @JsonProperty String encryptionAlgorithm, 38 | @JsonProperty String encryptionProvider) 39 | { 40 | this.fieldToKeyData = ImmutableMap.copyOf(requireNonNull(fieldToKeyData, "fieldToKeyData is null")); 41 | this.extraMetadata = ImmutableMap.copyOf(requireNonNull(extraMetadata, "extraMetadata is null")); 42 | this.encryptionAlgorithm = requireNonNull(encryptionAlgorithm, "encryptionAlgorithm is null"); 43 | this.encryptionProvider = requireNonNull(encryptionProvider, "encryptionProvider is null"); 44 | } 45 | 46 | @JsonProperty 47 | public Map getFieldToKeyData() 48 | { 49 | return fieldToKeyData; 50 | } 51 | 52 | @JsonProperty 53 | public Map getExtraMetadata() 54 | { 55 | return extraMetadata; 56 | } 57 | 58 | @JsonProperty 59 | public String getEncryptionAlgorithm() 60 | { 61 | return encryptionAlgorithm; 62 | } 63 | 64 | @JsonProperty 65 | public String getEncryptionProvider() 66 | { 67 | return encryptionProvider; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/hive/protocol/GlutenEncryptionInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.plugin.hive.protocol; 16 | 17 | import com.fasterxml.jackson.annotation.JsonCreator; 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | 20 | import java.util.Optional; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | 24 | public class GlutenEncryptionInformation 25 | { 26 | private final Optional dwrfEncryptionMetadata; 27 | 28 | // Only to be used by Jackson. Otherwise use {@link this#fromEncryptionMetadata} 29 | @JsonCreator 30 | public GlutenEncryptionInformation(@JsonProperty Optional dwrfEncryptionMetadata) 31 | { 32 | this.dwrfEncryptionMetadata = requireNonNull(dwrfEncryptionMetadata, "dwrfEncryptionMetadata is null"); 33 | } 34 | 35 | @JsonProperty 36 | public Optional getDwrfEncryptionMetadata() 37 | { 38 | return dwrfEncryptionMetadata; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/hive/protocol/GlutenEncryptionMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.plugin.hive.protocol; 16 | 17 | public interface GlutenEncryptionMetadata 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/hive/protocol/GlutenHiveTransactionHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.plugin.hive.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.spi.protocol.GlutenConnectorTransactionHandle; 19 | 20 | import java.util.Objects; 21 | import java.util.UUID; 22 | 23 | import static java.util.Objects.requireNonNull; 24 | 25 | public class GlutenHiveTransactionHandle 26 | implements GlutenConnectorTransactionHandle 27 | { 28 | private final UUID uuid; 29 | 30 | public GlutenHiveTransactionHandle() 31 | { 32 | this(UUID.randomUUID()); 33 | } 34 | 35 | @JsonCreator 36 | public GlutenHiveTransactionHandle(@JsonProperty("uuid") UUID uuid) 37 | { 38 | this.uuid = requireNonNull(uuid, "uuid is null"); 39 | } 40 | 41 | @JsonProperty 42 | public UUID getUuid() 43 | { 44 | return uuid; 45 | } 46 | 47 | @Override 48 | public boolean equals(Object obj) 49 | { 50 | if (this == obj) { 51 | return true; 52 | } 53 | if ((obj == null) || (getClass() != obj.getClass())) { 54 | return false; 55 | } 56 | GlutenHiveTransactionHandle other = (GlutenHiveTransactionHandle) obj; 57 | return Objects.equals(uuid, other.uuid); 58 | } 59 | 60 | @Override 61 | public int hashCode() 62 | { 63 | return Objects.hash(uuid); 64 | } 65 | 66 | @Override 67 | public String toString() 68 | { 69 | return uuid.toString(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/tpch/TpchColumnHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.plugin.tpch; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.plugin.tpch.protocol.GlutenTpchColumnHandle; 19 | import io.trino.spi.connector.ColumnHandle; 20 | import io.trino.spi.type.Type; 21 | 22 | import java.util.Objects; 23 | 24 | import static java.util.Objects.requireNonNull; 25 | 26 | public class TpchColumnHandle 27 | implements ColumnHandle 28 | { 29 | private final String columnName; 30 | private final Type type; 31 | 32 | @JsonCreator 33 | public TpchColumnHandle( 34 | @JsonProperty("columnName") String columnName, 35 | @JsonProperty("type") Type type) 36 | { 37 | this.columnName = requireNonNull(columnName, "columnName is null"); 38 | this.type = requireNonNull(type, "type is null"); 39 | } 40 | 41 | @JsonProperty 42 | public String getColumnName() 43 | { 44 | return columnName; 45 | } 46 | 47 | @JsonProperty 48 | public Type getType() 49 | { 50 | return type; 51 | } 52 | 53 | @Override 54 | public String toString() 55 | { 56 | return "tpch:" + columnName; 57 | } 58 | 59 | @Override 60 | public boolean equals(Object o) 61 | { 62 | if (this == o) { 63 | return true; 64 | } 65 | if ((o == null) || (getClass() != o.getClass())) { 66 | return false; 67 | } 68 | TpchColumnHandle other = (TpchColumnHandle) o; 69 | return Objects.equals(columnName, other.columnName); 70 | } 71 | 72 | @Override 73 | public int hashCode() 74 | { 75 | return Objects.hash(columnName); 76 | } 77 | 78 | @Override 79 | public GlutenTpchColumnHandle getProtocol() 80 | { 81 | return new GlutenTpchColumnHandle(columnName, type); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/tpch/TpchTransactionHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.plugin.tpch; 15 | 16 | import io.trino.plugin.tpch.protocol.GlutenTpchTransactionHandle; 17 | import io.trino.spi.connector.ConnectorTransactionHandle; 18 | 19 | public enum TpchTransactionHandle 20 | implements ConnectorTransactionHandle 21 | { 22 | INSTANCE; 23 | 24 | @Override 25 | public GlutenTpchTransactionHandle getProtocol() 26 | { 27 | return GlutenTpchTransactionHandle.INSTANCE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/tpch/protocol/GlutenTpchSplit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.plugin.tpch.protocol; 16 | 17 | import com.fasterxml.jackson.annotation.JsonCreator; 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | import com.google.common.collect.ImmutableList; 20 | import io.trino.spi.HostAddress; 21 | import io.trino.spi.protocol.GlutenConnectorSplit; 22 | 23 | import java.util.List; 24 | 25 | import static com.google.common.base.Preconditions.checkState; 26 | import static java.util.Objects.requireNonNull; 27 | 28 | public class GlutenTpchSplit 29 | implements GlutenConnectorSplit 30 | { 31 | // todo: provide tableHandle message. 32 | // private final GlutenTpchTableHandle tableHandle; 33 | private final int totalParts; 34 | private final int partNumber; 35 | private final List addresses; 36 | // todo: provide predicate message. 37 | // private final TupleDomain predicate; 38 | 39 | @JsonCreator 40 | public GlutenTpchSplit( 41 | @JsonProperty("partNumber") int partNumber, 42 | @JsonProperty("totalParts") int totalParts, 43 | @JsonProperty("addresses") List addresses) 44 | { 45 | checkState(partNumber >= 0, "partNumber must be >= 0"); 46 | checkState(totalParts >= 1, "totalParts must be >= 1"); 47 | checkState(totalParts > partNumber, "totalParts must be > partNumber"); 48 | 49 | this.partNumber = partNumber; 50 | this.totalParts = totalParts; 51 | this.addresses = ImmutableList.copyOf(requireNonNull(addresses, "addresses is null")); 52 | } 53 | 54 | @JsonProperty 55 | public int getTotalParts() 56 | { 57 | return totalParts; 58 | } 59 | 60 | @JsonProperty 61 | public int getPartNumber() 62 | { 63 | return partNumber; 64 | } 65 | 66 | @JsonProperty 67 | public List getAddresses() 68 | { 69 | return addresses; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/tpch/protocol/GlutenTpchTableHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.plugin.tpch.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.spi.protocol.GlutenConnectorTableHandle; 19 | 20 | import static java.util.Objects.requireNonNull; 21 | 22 | public final class GlutenTpchTableHandle 23 | implements GlutenConnectorTableHandle 24 | { 25 | private final String tableName; 26 | private final double scaleFactor; 27 | 28 | @JsonCreator 29 | public GlutenTpchTableHandle( 30 | @JsonProperty("tableName") String tableName, 31 | @JsonProperty("scaleFactor") double scaleFactor) 32 | { 33 | this.tableName = requireNonNull(tableName, "tableName is null"); 34 | this.scaleFactor = scaleFactor; 35 | } 36 | 37 | @JsonProperty 38 | public String getTableName() 39 | { 40 | return tableName; 41 | } 42 | 43 | @JsonProperty 44 | public double getScaleFactor() 45 | { 46 | return scaleFactor; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/tpch/protocol/GlutenTpchTableLayoutHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.plugin.tpch.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonProperty; 17 | import io.trino.spi.predicate.TupleDomain; 18 | import io.trino.spi.protocol.GlutenColumnHandle; 19 | import io.trino.spi.protocol.GlutenConnectorTableLayoutHandle; 20 | 21 | public final class GlutenTpchTableLayoutHandle 22 | implements GlutenConnectorTableLayoutHandle 23 | { 24 | private final GlutenTpchTableHandle table; 25 | private final TupleDomain predicate; 26 | 27 | public GlutenTpchTableLayoutHandle(GlutenTpchTableHandle table, TupleDomain predicate) 28 | { 29 | this.table = table; 30 | this.predicate = predicate; 31 | } 32 | 33 | @JsonProperty 34 | public GlutenTpchTableHandle getTable() 35 | { 36 | return table; 37 | } 38 | 39 | @JsonProperty 40 | public TupleDomain getPredicate() 41 | { 42 | return predicate; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/plugin/tpch/protocol/GlutenTpchTransactionHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.plugin.tpch.protocol; 15 | 16 | import io.trino.spi.protocol.GlutenConnectorTransactionHandle; 17 | 18 | public enum GlutenTpchTransactionHandle 19 | implements GlutenConnectorTransactionHandle 20 | { 21 | INSTANCE 22 | } 23 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/server/ServerPluginsProviderConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.server; 15 | 16 | import io.airlift.configuration.Config; 17 | 18 | import java.io.File; 19 | 20 | public class ServerPluginsProviderConfig 21 | { 22 | private File installedPluginsDir = new File("plugin"); 23 | 24 | private File trinoCppPluginsDir; 25 | 26 | public File getInstalledPluginsDir() 27 | { 28 | return installedPluginsDir; 29 | } 30 | 31 | public File getTrinoCppPluginsDir() 32 | { 33 | return trinoCppPluginsDir; 34 | } 35 | 36 | @Config("plugin.dir") 37 | public ServerPluginsProviderConfig setInstalledPluginsDir(File installedPluginsDir) 38 | { 39 | this.installedPluginsDir = installedPluginsDir; 40 | return this; 41 | } 42 | 43 | @Config("gluten-trino.plugin.dir") 44 | public ServerPluginsProviderConfig setTrinoCppPluginsDir(File trinoCppPluginsDir) 45 | { 46 | this.trinoCppPluginsDir = trinoCppPluginsDir; 47 | return this; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/connector/ColumnHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.spi.connector; 15 | 16 | import io.trino.spi.protocol.GlutenColumnHandle; 17 | 18 | /** 19 | * Represents a handle to a column within a {@link ConnectorTableHandle} returned from the connector to the engine. 20 | * It will be used by the engine whenever given column will be accessed. 21 | *

22 | * ColumnHandle should follow: 23 | *

    24 | *
  • a table cannot have two equal column handles
  • 25 | *
  • column handle is unique within a table scope. Two different tables can have two equal column handles
  • 26 | *
27 | */ 28 | public interface ColumnHandle 29 | { 30 | @Override 31 | int hashCode(); 32 | 33 | @Override 34 | boolean equals(Object other); 35 | 36 | default GlutenColumnHandle getProtocol() 37 | { 38 | throw new UnsupportedOperationException(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/connector/ConnectorSplit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.spi.connector; 15 | 16 | import io.trino.spi.HostAddress; 17 | import io.trino.spi.SplitWeight; 18 | import io.trino.spi.protocol.GlutenConnectorSplit; 19 | 20 | import java.util.List; 21 | 22 | public interface ConnectorSplit 23 | { 24 | /** 25 | * Returns true when this ConnectorSplit can be scheduled on any node. 26 | *

27 | * When true, the addresses returned by {@link #getAddresses()} may be used as hints by the scheduler 28 | * during splits assignment. 29 | * When false, the split will always be scheduled on one of the addresses returned by {@link #getAddresses()}. 30 | */ 31 | boolean isRemotelyAccessible(); 32 | 33 | List getAddresses(); 34 | 35 | Object getInfo(); 36 | 37 | default SplitWeight getSplitWeight() 38 | { 39 | return SplitWeight.standard(); 40 | } 41 | 42 | default long getRetainedSizeInBytes() 43 | { 44 | throw new UnsupportedOperationException("This connector does not provide memory accounting capabilities for ConnectorSplit"); 45 | } 46 | 47 | default GlutenConnectorSplit getProtocol() 48 | { 49 | throw new UnsupportedOperationException(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/connector/ConnectorTableHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.spi.connector; 15 | 16 | import io.trino.spi.protocol.GlutenConnectorTableHandle; 17 | 18 | /** 19 | * Represents a handle to a relation returned from the connector to the engine. 20 | * It will be used by the engine whenever given relation will be accessed. 21 | */ 22 | public interface ConnectorTableHandle 23 | { 24 | default GlutenConnectorTableHandle getProtocol() 25 | { 26 | String errorMessage = "Getting protocol for " + this.getClass().getSimpleName() + " is unsupported"; 27 | throw new UnsupportedOperationException(errorMessage); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/connector/ConnectorTransactionHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.spi.connector; 15 | 16 | import io.trino.spi.protocol.GlutenConnectorTransactionHandle; 17 | 18 | public interface ConnectorTransactionHandle 19 | { 20 | default GlutenConnectorTransactionHandle getProtocol() 21 | { 22 | throw new UnsupportedOperationException("The subclass of ConnectorTransactionHandle has not yet implemented the function"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/protocol/GlutenColumnHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.spi.protocol; 16 | 17 | public interface GlutenColumnHandle 18 | { 19 | /** 20 | * Support to modify glutened ColumnHandle to fix the difference between Trino and Velox. 21 | * 22 | * @param tableHandle table's name. 23 | * @return final GlutenColumnHandle. 24 | */ 25 | default GlutenColumnHandle refine(GlutenConnectorTableHandle tableHandle) 26 | { 27 | return this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/protocol/GlutenConnectorSplit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.spi.protocol; 16 | 17 | public interface GlutenConnectorSplit 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/protocol/GlutenConnectorTableHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.spi.protocol; 15 | 16 | public interface GlutenConnectorTableHandle 17 | { 18 | } 19 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/protocol/GlutenConnectorTableLayoutHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.spi.protocol; 15 | 16 | public interface GlutenConnectorTableLayoutHandle 17 | { 18 | } 19 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/protocol/GlutenConnectorTransactionHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.spi.protocol; 15 | 16 | public interface GlutenConnectorTransactionHandle 17 | { 18 | } 19 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/protocol/GlutenDomain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.spi.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | 19 | import static java.util.Objects.requireNonNull; 20 | 21 | public final class GlutenDomain 22 | { 23 | private final GlutenValueSet values; 24 | private final boolean nullAllowed; 25 | 26 | private GlutenDomain(GlutenValueSet values, boolean nullAllowed) 27 | { 28 | this.values = requireNonNull(values, "values is null"); 29 | this.nullAllowed = nullAllowed; 30 | } 31 | 32 | @JsonCreator 33 | public static GlutenDomain create( 34 | @JsonProperty("values") GlutenValueSet values, 35 | @JsonProperty("nullAllowed") boolean nullAllowed) 36 | { 37 | return new GlutenDomain(values, nullAllowed); 38 | } 39 | 40 | @JsonProperty 41 | public GlutenValueSet getValues() 42 | { 43 | return values; 44 | } 45 | 46 | @JsonProperty 47 | public boolean isNullAllowed() 48 | { 49 | return nullAllowed; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/protocol/GlutenNodeSelectionStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.spi.protocol; 16 | 17 | public enum GlutenNodeSelectionStrategy 18 | { 19 | HARD_AFFINITY, 20 | SOFT_AFFINITY, 21 | NO_PREFERENCE 22 | } 23 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/protocol/GlutenRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.spi.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.spi.predicate.GlutenMarker; 19 | 20 | import static java.util.Objects.requireNonNull; 21 | 22 | public class GlutenRange 23 | { 24 | private final GlutenMarker low; 25 | private final GlutenMarker high; 26 | 27 | @JsonCreator 28 | public GlutenRange( 29 | @JsonProperty("low") GlutenMarker low, 30 | @JsonProperty("high") GlutenMarker high) 31 | { 32 | this(low, high, () -> { 33 | if (low.compareTo(high) > 0) { 34 | throw new IllegalArgumentException("low must be less than or equal to high"); 35 | } 36 | }); 37 | } 38 | 39 | private GlutenRange(GlutenMarker low, GlutenMarker high, Runnable extraCheck) 40 | { 41 | requireNonNull(low, "value is null"); 42 | requireNonNull(high, "value is null"); 43 | if (!low.getType().equals(high.getType())) { 44 | throw new IllegalArgumentException(String.format("Marker types do not match: %s vs %s", low.getType(), high.getType())); 45 | } 46 | if (low.getBound() == GlutenMarker.Bound.BELOW) { 47 | throw new IllegalArgumentException("low bound must be EXACTLY or ABOVE"); 48 | } 49 | if (high.getBound() == GlutenMarker.Bound.ABOVE) { 50 | throw new IllegalArgumentException("high bound must be EXACTLY or BELOW"); 51 | } 52 | extraCheck.run(); 53 | this.low = low; 54 | this.high = high; 55 | } 56 | 57 | @JsonProperty 58 | public GlutenMarker getLow() 59 | { 60 | return low; 61 | } 62 | 63 | @JsonProperty 64 | public GlutenMarker getHigh() 65 | { 66 | return high; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/spi/protocol/GlutenValueSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.spi.protocol; 16 | 17 | import com.fasterxml.jackson.annotation.JsonSubTypes; 18 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 19 | import io.trino.spi.type.Type; 20 | 21 | @JsonTypeInfo( 22 | use = JsonTypeInfo.Id.NAME, 23 | include = JsonTypeInfo.As.PROPERTY, 24 | property = "@type") 25 | @JsonSubTypes({ 26 | @JsonSubTypes.Type(value = GlutenEquatableValueSet.class, name = "equatable"), 27 | @JsonSubTypes.Type(value = GlutenSortedRangeSet.class, name = "sortable"), 28 | @JsonSubTypes.Type(value = GlutenAllOrNoneValueSet.class, name = "allOrNone")}) 29 | public interface GlutenValueSet 30 | { 31 | Type getType(); 32 | } 33 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/split/EmptySplit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.split; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import com.google.common.collect.ImmutableList; 19 | import io.trino.spi.HostAddress; 20 | import io.trino.spi.connector.CatalogHandle; 21 | import io.trino.spi.connector.ConnectorSplit; 22 | import io.trino.velox.protocol.GlutenConnectorId; 23 | import io.trino.velox.protocol.GlutenEmptySplit; 24 | 25 | import java.util.List; 26 | 27 | import static io.airlift.slice.SizeOf.instanceSize; 28 | import static java.util.Objects.requireNonNull; 29 | 30 | public class EmptySplit 31 | implements ConnectorSplit 32 | { 33 | private static final int INSTANCE_SIZE = instanceSize(EmptySplit.class); 34 | 35 | private final CatalogHandle catalogHandle; 36 | 37 | @JsonCreator 38 | public EmptySplit( 39 | @JsonProperty("catalogHandle") CatalogHandle catalogHandle) 40 | { 41 | this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null"); 42 | } 43 | 44 | @Override 45 | public boolean isRemotelyAccessible() 46 | { 47 | return true; 48 | } 49 | 50 | @Override 51 | public List getAddresses() 52 | { 53 | return ImmutableList.of(); 54 | } 55 | 56 | @Override 57 | public Object getInfo() 58 | { 59 | return this; 60 | } 61 | 62 | @Override 63 | public long getRetainedSizeInBytes() 64 | { 65 | return INSTANCE_SIZE + catalogHandle.getRetainedSizeInBytes(); 66 | } 67 | 68 | @JsonProperty 69 | public CatalogHandle getCatalogHandle() 70 | { 71 | return catalogHandle; 72 | } 73 | 74 | @Override 75 | public GlutenEmptySplit getProtocol() 76 | { 77 | return new GlutenEmptySplit(new GlutenConnectorId(catalogHandle.getCatalogName())); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenAssignUniqueId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import com.google.common.collect.ImmutableList; 19 | import io.trino.sql.planner.plan.PlanNodeId; 20 | 21 | import java.util.List; 22 | 23 | import static java.util.Objects.requireNonNull; 24 | 25 | public class GlutenAssignUniqueId 26 | extends GlutenPlanNode 27 | { 28 | private final GlutenPlanNode source; 29 | private final GlutenVariableReferenceExpression idVariable; 30 | 31 | @JsonCreator 32 | public GlutenAssignUniqueId( 33 | @JsonProperty("id") PlanNodeId id, 34 | @JsonProperty("source") GlutenPlanNode source, 35 | @JsonProperty("idVariable") GlutenVariableReferenceExpression idVariable) 36 | { 37 | super(id); 38 | this.source = requireNonNull(source, "source is null"); 39 | this.idVariable = requireNonNull(idVariable, "idVariable is null"); 40 | } 41 | 42 | @JsonProperty 43 | public GlutenPlanNode getSource() 44 | { 45 | return source; 46 | } 47 | 48 | public List getSources() 49 | { 50 | return ImmutableList.of(source); 51 | } 52 | 53 | @JsonProperty 54 | public GlutenVariableReferenceExpression getIdVariable() 55 | { 56 | return idVariable; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenAssignments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | 19 | import java.util.Map; 20 | 21 | public class GlutenAssignments 22 | { 23 | private final Map assignments; 24 | 25 | @JsonCreator 26 | public GlutenAssignments(@JsonProperty("assignments") Map assignments) 27 | { 28 | this.assignments = assignments; 29 | } 30 | 31 | @JsonProperty 32 | public Map getAssignments() 33 | { 34 | return assignments; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenBuiltInFunctionHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | 19 | public final class GlutenBuiltInFunctionHandle 20 | implements GlutenFunctionHandle 21 | { 22 | private final GlutenSignature signature; 23 | 24 | @JsonCreator 25 | public GlutenBuiltInFunctionHandle(@JsonProperty("signature") GlutenSignature signature) 26 | { 27 | this.signature = signature; 28 | } 29 | 30 | @JsonProperty 31 | public GlutenSignature getSignature() 32 | { 33 | return signature; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenCallExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.spi.type.Type; 19 | 20 | import java.util.List; 21 | 22 | public final class GlutenCallExpression 23 | extends GlutenRowExpression 24 | { 25 | private final String displayName; 26 | private final GlutenFunctionHandle functionHandle; 27 | private final Type returnType; 28 | private final List arguments; 29 | 30 | @JsonCreator 31 | public GlutenCallExpression(@JsonProperty("displayName") String displayName, 32 | @JsonProperty("functionHandle") GlutenFunctionHandle functionHandle, 33 | @JsonProperty("returnType") Type returnType, 34 | @JsonProperty("arguments") List arguments) 35 | { 36 | this.displayName = displayName; 37 | this.functionHandle = functionHandle; 38 | this.returnType = returnType; 39 | this.arguments = arguments; 40 | } 41 | 42 | @JsonProperty 43 | public String getDisplayName() 44 | { 45 | return displayName; 46 | } 47 | 48 | @JsonProperty 49 | public GlutenFunctionHandle getFunctionHandle() 50 | { 51 | return functionHandle; 52 | } 53 | 54 | @Override 55 | @JsonProperty("returnType") 56 | public Type getType() 57 | { 58 | return returnType; 59 | } 60 | 61 | @JsonProperty 62 | public List getArguments() 63 | { 64 | return arguments; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenCatalogProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | 19 | import java.util.Map; 20 | 21 | public class GlutenCatalogProperties 22 | { 23 | private final String catalogName; 24 | private final String connectorName; 25 | private final Map properties; 26 | 27 | @JsonCreator 28 | public GlutenCatalogProperties(@JsonProperty String catalogName, 29 | @JsonProperty String connectorName, 30 | @JsonProperty Map properties) 31 | { 32 | this.catalogName = catalogName; 33 | this.connectorName = connectorName; 34 | this.properties = properties; 35 | } 36 | 37 | @JsonProperty 38 | public String getCatalogName() 39 | { 40 | return catalogName; 41 | } 42 | 43 | @JsonProperty 44 | public String getConnectorName() 45 | { 46 | return connectorName; 47 | } 48 | 49 | @JsonProperty 50 | public Map getProperties() 51 | { 52 | return properties; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenConnectorId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | 19 | public class GlutenConnectorId 20 | { 21 | private final String catalogName; 22 | 23 | @JsonCreator 24 | public GlutenConnectorId(@JsonProperty("catalogName") String catalogName) 25 | { 26 | this.catalogName = catalogName; 27 | } 28 | 29 | @JsonProperty 30 | public String getCatalogName() 31 | { 32 | return catalogName; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenConstantExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.spi.block.Block; 19 | import io.trino.spi.predicate.Utils; 20 | import io.trino.spi.type.Type; 21 | 22 | public final class GlutenConstantExpression 23 | extends GlutenRowExpression 24 | { 25 | private final Object value; 26 | private final Type type; 27 | 28 | @JsonCreator 29 | public GlutenConstantExpression(@JsonProperty("valueBlock") Block valueBlock, 30 | @JsonProperty("type") Type type) 31 | { 32 | this.value = Utils.blockToNativeValue(type, valueBlock); 33 | this.type = type; 34 | } 35 | 36 | public GlutenConstantExpression(Object value, Type type) 37 | { 38 | this.value = value; 39 | this.type = type; 40 | } 41 | 42 | @Override 43 | @JsonProperty 44 | public Type getType() 45 | { 46 | return type; 47 | } 48 | 49 | @JsonProperty 50 | public Block getValueBlock() 51 | { 52 | return Utils.nativeValueToBlock(type, value); 53 | } 54 | 55 | public Object getValue() 56 | { 57 | return value; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenEmptySplit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.spi.protocol.GlutenConnectorSplit; 19 | 20 | import static java.util.Objects.requireNonNull; 21 | 22 | public class GlutenEmptySplit 23 | implements GlutenConnectorSplit 24 | { 25 | private final GlutenConnectorId connectorId; 26 | 27 | @JsonCreator 28 | public GlutenEmptySplit( 29 | @JsonProperty("connectorId") GlutenConnectorId connectorId) 30 | { 31 | this.connectorId = requireNonNull(connectorId, "connectorId is null"); 32 | } 33 | 34 | @JsonProperty 35 | public GlutenConnectorId getConnectorId() 36 | { 37 | return connectorId; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenEnforceSingleRowNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.sql.planner.plan.PlanNodeId; 19 | 20 | import static java.util.Objects.requireNonNull; 21 | 22 | public class GlutenEnforceSingleRowNode 23 | extends GlutenPlanNode 24 | { 25 | private final GlutenPlanNode source; 26 | 27 | @JsonCreator 28 | public GlutenEnforceSingleRowNode( 29 | @JsonProperty("id") PlanNodeId id, 30 | @JsonProperty("source") GlutenPlanNode source) 31 | { 32 | super(id); 33 | this.source = requireNonNull(source, "source is null"); 34 | } 35 | 36 | @JsonProperty("source") 37 | public GlutenPlanNode getSource() 38 | { 39 | return source; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenFilterNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.sql.planner.plan.PlanNodeId; 19 | 20 | public final class GlutenFilterNode 21 | extends GlutenPlanNode 22 | { 23 | private final GlutenPlanNode source; 24 | private final GlutenRowExpression predicate; 25 | 26 | @JsonCreator 27 | public GlutenFilterNode(@JsonProperty("id") PlanNodeId id, 28 | @JsonProperty("source") GlutenPlanNode source, 29 | @JsonProperty("predicate") GlutenRowExpression predicate) 30 | { 31 | super(id); 32 | this.source = source; 33 | this.predicate = predicate; 34 | } 35 | 36 | @JsonProperty 37 | public GlutenPlanNode getSource() 38 | { 39 | return source; 40 | } 41 | 42 | @JsonProperty 43 | public GlutenRowExpression getPredicate() 44 | { 45 | return predicate; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenFunctionHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonSubTypes; 17 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 18 | 19 | @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "@type") 20 | @JsonSubTypes({@JsonSubTypes.Type(value = GlutenBuiltInFunctionHandle.class, name = "static")}) 21 | public interface GlutenFunctionHandle 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenLocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | 19 | import java.net.URI; 20 | 21 | import static java.util.Objects.requireNonNull; 22 | 23 | public class GlutenLocation 24 | { 25 | private final String location; 26 | 27 | @JsonCreator 28 | public GlutenLocation(@JsonProperty("location") String location) 29 | { 30 | this.location = requireNonNull(location, "location is null"); 31 | } 32 | 33 | @JsonProperty 34 | public String getLocation() 35 | { 36 | return location; 37 | } 38 | 39 | // TODO: Remove this once URI is replaced 40 | public URI toURI() 41 | { 42 | return URI.create(location); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenOrderingScheme.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.spi.connector.SortOrder; 19 | 20 | import java.util.List; 21 | 22 | import static com.google.common.collect.ImmutableList.toImmutableList; 23 | 24 | public class GlutenOrderingScheme 25 | { 26 | private final List orderBy; 27 | 28 | @JsonCreator 29 | public GlutenOrderingScheme(@JsonProperty("orderBy") List orderBy) 30 | { 31 | this.orderBy = orderBy; 32 | } 33 | 34 | @JsonProperty 35 | public List getOrderBy() 36 | { 37 | return orderBy; 38 | } 39 | 40 | public List getOrderByVariables() 41 | { 42 | return orderBy.stream().map(Ordering::getVariable).collect(toImmutableList()); 43 | } 44 | 45 | public static class Ordering 46 | { 47 | private final GlutenVariableReferenceExpression variable; 48 | private final SortOrder sortOrder; 49 | 50 | @JsonCreator 51 | public Ordering(@JsonProperty("variable") GlutenVariableReferenceExpression variable, 52 | @JsonProperty("sortOrder") SortOrder sortOrder) 53 | { 54 | this.variable = variable; 55 | this.sortOrder = sortOrder; 56 | } 57 | 58 | @JsonProperty 59 | public GlutenVariableReferenceExpression getVariable() 60 | { 61 | return variable; 62 | } 63 | 64 | @JsonProperty 65 | public SortOrder getSortOrder() 66 | { 67 | return sortOrder; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenOutputNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import com.google.common.collect.ImmutableList; 19 | import io.trino.sql.planner.plan.PlanNodeId; 20 | 21 | import java.util.List; 22 | 23 | public class GlutenOutputNode 24 | extends GlutenPlanNode 25 | { 26 | private final GlutenPlanNode source; 27 | private final List columnNames; 28 | private final List outputVariables; // column name = variable.name 29 | 30 | @JsonCreator 31 | public GlutenOutputNode(@JsonProperty PlanNodeId id, @JsonProperty GlutenPlanNode source, @JsonProperty List columnNames, @JsonProperty List outputVariables) 32 | { 33 | super(id); 34 | this.source = source; 35 | this.columnNames = columnNames; 36 | this.outputVariables = outputVariables; 37 | } 38 | 39 | public List getSources() 40 | { 41 | return ImmutableList.of(source); 42 | } 43 | 44 | @JsonProperty 45 | public List getOutputVariables() 46 | { 47 | return outputVariables; 48 | } 49 | 50 | @JsonProperty 51 | public List getColumnNames() 52 | { 53 | return columnNames; 54 | } 55 | 56 | @JsonProperty 57 | public GlutenPlanNode getSource() 58 | { 59 | return source; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenPartitioning.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | 19 | import java.util.List; 20 | 21 | public class GlutenPartitioning 22 | { 23 | private final GlutenPartitioningHandle handle; 24 | private final List arguments; 25 | 26 | @JsonCreator 27 | public GlutenPartitioning(@JsonProperty("handle") GlutenPartitioningHandle handle, 28 | @JsonProperty("arguments") List arguments) 29 | { 30 | this.handle = handle; 31 | this.arguments = arguments; 32 | } 33 | 34 | @JsonProperty 35 | public GlutenPartitioningHandle getHandle() 36 | { 37 | return handle; 38 | } 39 | 40 | @JsonProperty 41 | public List getArguments() 42 | { 43 | return arguments; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenPartitioningHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.velox.protocol; 16 | 17 | import com.fasterxml.jackson.annotation.JsonCreator; 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | import io.trino.spi.connector.ConnectorPartitioningHandle; 20 | import io.trino.spi.protocol.GlutenConnectorTransactionHandle; 21 | 22 | import java.util.Optional; 23 | 24 | import static com.google.common.base.Preconditions.checkArgument; 25 | import static java.util.Objects.requireNonNull; 26 | 27 | public class GlutenPartitioningHandle 28 | { 29 | private final Optional connectorId; 30 | private final Optional transactionHandle; 31 | private final ConnectorPartitioningHandle connectorHandle; 32 | 33 | @JsonCreator 34 | public GlutenPartitioningHandle( 35 | @JsonProperty("connectorId") Optional connectorId, 36 | @JsonProperty("transactionHandle") Optional transactionHandle, 37 | @JsonProperty("connectorHandle") ConnectorPartitioningHandle connectorHandle) 38 | { 39 | this.connectorId = requireNonNull(connectorId, "connectorId is null"); 40 | this.transactionHandle = requireNonNull(transactionHandle, "transactionHandle is null"); 41 | checkArgument(!connectorId.isPresent() || transactionHandle.isPresent(), "transactionHandle is required when connectorId is present"); 42 | this.connectorHandle = requireNonNull(connectorHandle, "connectorHandle is null"); 43 | } 44 | 45 | @JsonProperty 46 | public Optional getConnectorId() 47 | { 48 | return connectorId; 49 | } 50 | 51 | @JsonProperty 52 | public Optional getTransactionHandle() 53 | { 54 | return transactionHandle; 55 | } 56 | 57 | @JsonProperty 58 | public ConnectorPartitioningHandle getConnectorHandle() 59 | { 60 | return connectorHandle; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenPartitioningScheme.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | 19 | import java.util.List; 20 | import java.util.Optional; 21 | 22 | public class GlutenPartitioningScheme 23 | { 24 | private final GlutenPartitioning partitioning; 25 | private final List outputLayout; 26 | // TBD: hashColumn isn't used in presto-cpp 27 | private final boolean replicateNullsAndAny; 28 | private final Optional bucketToPartition; 29 | 30 | @JsonCreator 31 | public GlutenPartitioningScheme(@JsonProperty("partitioning") GlutenPartitioning partitioning, 32 | @JsonProperty("outputLayout") List outputLayout, 33 | @JsonProperty("replicateNullsAndAny") boolean replicateNullsAndAny, 34 | @JsonProperty("bucketToPartition") Optional bucketToPartition) 35 | { 36 | this.partitioning = partitioning; 37 | this.outputLayout = outputLayout; 38 | this.replicateNullsAndAny = replicateNullsAndAny; 39 | this.bucketToPartition = bucketToPartition; 40 | } 41 | 42 | @JsonProperty 43 | public GlutenPartitioning getPartitioning() 44 | { 45 | return partitioning; 46 | } 47 | 48 | @JsonProperty 49 | public List getOutputLayout() 50 | { 51 | return outputLayout; 52 | } 53 | 54 | @JsonProperty 55 | public boolean isReplicateNullsAndAny() 56 | { 57 | return replicateNullsAndAny; 58 | } 59 | 60 | @JsonProperty 61 | public Optional getBucketToPartition() 62 | { 63 | return bucketToPartition; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenPlanFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.sql.planner.plan.PlanFragmentId; 19 | 20 | public class GlutenPlanFragment 21 | { 22 | private final PlanFragmentId id; 23 | private final GlutenPlanNode root; 24 | private final GlutenPartitioningScheme partitionScheme; 25 | // TODO: No StageExecutionDescriptor corresponding concept in trino, to modify cpp conversion code as default. 26 | 27 | @JsonCreator 28 | public GlutenPlanFragment(@JsonProperty("id") PlanFragmentId id, 29 | @JsonProperty("root") GlutenPlanNode root, 30 | @JsonProperty("partitioningScheme") GlutenPartitioningScheme partitionScheme) 31 | { 32 | this.id = id; 33 | this.root = root; 34 | this.partitionScheme = partitionScheme; 35 | } 36 | 37 | @JsonProperty 38 | public PlanFragmentId getId() 39 | { 40 | return id; 41 | } 42 | 43 | @JsonProperty 44 | public GlutenPlanNode getRoot() 45 | { 46 | return root; 47 | } 48 | 49 | @JsonProperty 50 | public GlutenPartitioningScheme getPartitionScheme() 51 | { 52 | return partitionScheme; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenProjectNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.sql.planner.plan.PlanNodeId; 19 | 20 | public final class GlutenProjectNode 21 | extends GlutenPlanNode 22 | { 23 | private final GlutenPlanNode source; 24 | private final GlutenAssignments assignments; 25 | private final Locality locality = Locality.LOCAL; 26 | 27 | @JsonCreator 28 | public GlutenProjectNode(@JsonProperty("id") PlanNodeId id, 29 | @JsonProperty("source") GlutenPlanNode source, 30 | @JsonProperty("assignments") GlutenAssignments assignments, 31 | @JsonProperty("locality") Locality locality) 32 | { 33 | this(id, source, assignments); 34 | } 35 | 36 | public GlutenProjectNode(PlanNodeId id, 37 | GlutenPlanNode source, 38 | GlutenAssignments assignments) 39 | { 40 | super(id); 41 | this.source = source; 42 | this.assignments = assignments; 43 | } 44 | 45 | @JsonProperty 46 | public GlutenPlanNode getSource() 47 | { 48 | return source; 49 | } 50 | 51 | @JsonProperty 52 | public GlutenAssignments getAssignments() 53 | { 54 | return assignments; 55 | } 56 | 57 | @JsonProperty 58 | public Locality getLocality() 59 | { 60 | return locality; 61 | } 62 | 63 | public enum Locality 64 | { 65 | UNKNOWN, 66 | LOCAL, 67 | REMOTE, 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenRemoteSplit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.execution.TaskId; 19 | import io.trino.spi.protocol.GlutenConnectorSplit; 20 | 21 | import static com.google.common.base.MoreObjects.toStringHelper; 22 | import static java.util.Objects.requireNonNull; 23 | 24 | public class GlutenRemoteSplit 25 | implements GlutenConnectorSplit 26 | { 27 | private final GlutenLocation location; 28 | private final TaskId remoteSourceTaskId; 29 | 30 | @JsonCreator 31 | public GlutenRemoteSplit(@JsonProperty("location") GlutenLocation location, @JsonProperty("remoteSourceTaskId") TaskId remoteSourceTaskId) 32 | { 33 | this.location = requireNonNull(location, "location is null"); 34 | this.remoteSourceTaskId = requireNonNull(remoteSourceTaskId, "remoteSourceTaskId is null"); 35 | } 36 | 37 | @JsonProperty 38 | public GlutenLocation getLocation() 39 | { 40 | return location; 41 | } 42 | 43 | @JsonProperty 44 | public TaskId getRemoteSourceTaskId() 45 | { 46 | return remoteSourceTaskId; 47 | } 48 | 49 | @Override 50 | public String toString() 51 | { 52 | return toStringHelper(this) 53 | .add("location", location) 54 | .add("remoteSourceTaskId", remoteSourceTaskId) 55 | .toString(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenRowExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonSubTypes; 17 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 18 | import io.trino.spi.type.Type; 19 | 20 | @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "@type") 21 | @JsonSubTypes({ 22 | @JsonSubTypes.Type(value = GlutenVariableReferenceExpression.class, name = "variable"), 23 | @JsonSubTypes.Type(value = GlutenCallExpression.class, name = "call"), 24 | @JsonSubTypes.Type(value = GlutenConstantExpression.class, name = "constant"), 25 | @JsonSubTypes.Type(value = GlutenSpecialFormExpression.class, name = "special") 26 | }) 27 | public abstract class GlutenRowExpression 28 | { 29 | public abstract Type getType(); 30 | } 31 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenSortNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import com.google.common.collect.ImmutableList; 19 | import io.trino.sql.planner.plan.PlanNodeId; 20 | 21 | import java.util.List; 22 | 23 | import static java.util.Objects.requireNonNull; 24 | 25 | public class GlutenSortNode 26 | extends GlutenPlanNode 27 | { 28 | private final GlutenPlanNode source; 29 | private final GlutenOrderingScheme orderingScheme; 30 | private final boolean isPartial; 31 | 32 | @JsonCreator 33 | public GlutenSortNode( 34 | @JsonProperty("id") PlanNodeId id, 35 | @JsonProperty("source") GlutenPlanNode source, 36 | @JsonProperty("orderingScheme") GlutenOrderingScheme orderingScheme, 37 | @JsonProperty("isPartial") boolean isPartial) 38 | { 39 | super(id); 40 | 41 | requireNonNull(source, "source is null"); 42 | requireNonNull(orderingScheme, "orderingScheme is null"); 43 | 44 | this.source = source; 45 | this.orderingScheme = orderingScheme; 46 | this.isPartial = isPartial; 47 | } 48 | 49 | public List getSources() 50 | { 51 | return ImmutableList.of(source); 52 | } 53 | 54 | @JsonProperty("source") 55 | public GlutenPlanNode getSource() 56 | { 57 | return source; 58 | } 59 | 60 | @JsonProperty("orderingScheme") 61 | public GlutenOrderingScheme getOrderingScheme() 62 | { 63 | return orderingScheme; 64 | } 65 | 66 | @JsonProperty("isPartial") 67 | public boolean isPartial() 68 | { 69 | return isPartial; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenSpecialFormExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.spi.type.Type; 19 | 20 | import java.util.List; 21 | 22 | public final class GlutenSpecialFormExpression 23 | extends GlutenRowExpression 24 | { 25 | private final Form form; 26 | private final Type returnType; 27 | private final List arguments; 28 | 29 | @JsonCreator 30 | public GlutenSpecialFormExpression(@JsonProperty("form") Form form, 31 | @JsonProperty("returnType") Type returnType, 32 | @JsonProperty("arguments") List arguments) 33 | { 34 | this.form = form; 35 | this.returnType = returnType; 36 | this.arguments = arguments; 37 | } 38 | 39 | @Override 40 | @JsonProperty("returnType") 41 | public Type getType() 42 | { 43 | return returnType; 44 | } 45 | 46 | @JsonProperty 47 | public Form getForm() 48 | { 49 | return form; 50 | } 51 | 52 | @JsonProperty 53 | public List getArguments() 54 | { 55 | return arguments; 56 | } 57 | 58 | public enum Form 59 | { 60 | IF, 61 | NULL_IF, 62 | SWITCH, 63 | WHEN, 64 | IS_NULL, 65 | COALESCE, 66 | IN, 67 | AND, 68 | OR, 69 | DEREFERENCE, 70 | ROW_CONSTRUCTOR, 71 | BIND, 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenSplit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.metadata.Split; 19 | import io.trino.spi.protocol.GlutenConnectorSplit; 20 | 21 | import static java.util.Objects.requireNonNull; 22 | 23 | public class GlutenSplit 24 | { 25 | private final GlutenConnectorId connectorId; 26 | private final GlutenConnectorSplit connectorSplit; 27 | 28 | @JsonCreator 29 | public GlutenSplit( 30 | @JsonProperty("connectorId") GlutenConnectorId connectorId, 31 | @JsonProperty("connectorSplit") GlutenConnectorSplit connectorSplit) 32 | { 33 | this.connectorId = requireNonNull(connectorId, "connectorId is null"); 34 | this.connectorSplit = requireNonNull(connectorSplit, "connectorSplit is null"); 35 | } 36 | 37 | public static GlutenSplit create(Split split) 38 | { 39 | GlutenConnectorId connectorId = new GlutenConnectorId(split.getCatalogHandle().getCatalogName()); 40 | GlutenConnectorSplit glutenConnectorSplit = split.getConnectorSplit().getProtocol(); 41 | return new GlutenSplit(connectorId, glutenConnectorSplit); 42 | } 43 | 44 | @JsonProperty 45 | public GlutenConnectorId getConnectorId() 46 | { 47 | return connectorId; 48 | } 49 | 50 | @JsonProperty 51 | public GlutenConnectorSplit getConnectorSplit() 52 | { 53 | return connectorSplit; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenTableHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.spi.protocol.GlutenConnectorTableHandle; 19 | import io.trino.spi.protocol.GlutenConnectorTransactionHandle; 20 | 21 | public final class GlutenTableHandle 22 | { 23 | private final GlutenConnectorId connectorId; 24 | // TODO: Push-downed predicates are hold by ConnectorTableHandle, need to modify cpp code to adapt this. 25 | private final GlutenConnectorTableHandle connectorHandle; 26 | private final GlutenConnectorTransactionHandle transaction; 27 | 28 | @JsonCreator 29 | public GlutenTableHandle(@JsonProperty("connectorId") GlutenConnectorId connectorId, 30 | @JsonProperty("connectorHandle") GlutenConnectorTableHandle connectorHandle, 31 | @JsonProperty("transaction") GlutenConnectorTransactionHandle transaction) 32 | { 33 | this.connectorId = connectorId; 34 | this.connectorHandle = connectorHandle; 35 | this.transaction = transaction; 36 | } 37 | 38 | @JsonProperty 39 | public GlutenConnectorId getConnectorId() 40 | { 41 | return connectorId; 42 | } 43 | 44 | @JsonProperty 45 | public GlutenConnectorTableHandle getConnectorHandle() 46 | { 47 | return connectorHandle; 48 | } 49 | 50 | @JsonProperty 51 | public GlutenConnectorTransactionHandle getTransaction() 52 | { 53 | return transaction; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenTableScanNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.spi.protocol.GlutenColumnHandle; 19 | import io.trino.sql.planner.plan.PlanNodeId; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | public class GlutenTableScanNode 25 | extends GlutenPlanNode 26 | { 27 | private final GlutenTableHandle table; 28 | private final Map assignments; 29 | private final List outputVariables; 30 | 31 | @JsonCreator 32 | public GlutenTableScanNode(@JsonProperty("id") PlanNodeId id, 33 | @JsonProperty("table") GlutenTableHandle table, 34 | @JsonProperty("assignments") Map assignments, 35 | @JsonProperty("outputVariables") List outputVariables) 36 | { 37 | super(id); 38 | this.table = table; 39 | this.assignments = assignments; 40 | this.outputVariables = outputVariables; 41 | } 42 | 43 | @JsonProperty 44 | public GlutenTableHandle getTable() 45 | { 46 | return table; 47 | } 48 | 49 | @JsonProperty 50 | public Map getAssignments() 51 | { 52 | return assignments; 53 | } 54 | 55 | @JsonProperty 56 | public List getOutputVariables() 57 | { 58 | return outputVariables; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenVariableExpressionSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.core.JsonGenerator; 17 | import com.fasterxml.jackson.databind.JsonSerializer; 18 | import com.fasterxml.jackson.databind.SerializerProvider; 19 | 20 | import java.io.IOException; 21 | 22 | import static java.lang.String.format; 23 | 24 | public class GlutenVariableExpressionSerializer 25 | extends JsonSerializer 26 | { 27 | private static final char VARIABLE_TYPE_OPEN_BRACKET = '<'; 28 | private static final char VARIABLE_TYPE_CLOSE_BRACKET = '>'; 29 | 30 | @Override 31 | public void serialize(GlutenVariableReferenceExpression value, JsonGenerator gen, SerializerProvider serializers) 32 | throws IOException 33 | { 34 | gen.writeFieldName(format("%s%s%s%s", value.getName(), VARIABLE_TYPE_OPEN_BRACKET, value.getType().getTypeSignature(), VARIABLE_TYPE_CLOSE_BRACKET)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/GlutenVariableReferenceExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.spi.type.Type; 19 | 20 | import java.util.Objects; 21 | 22 | public class GlutenVariableReferenceExpression 23 | extends GlutenRowExpression 24 | { 25 | private final String name; 26 | private final Type type; 27 | 28 | @JsonCreator 29 | public GlutenVariableReferenceExpression(@JsonProperty("name") String name, 30 | @JsonProperty("type") Type type) 31 | { 32 | this.name = name; 33 | this.type = type; 34 | } 35 | 36 | @JsonProperty 37 | public String getName() 38 | { 39 | return name; 40 | } 41 | 42 | @Override 43 | @JsonProperty 44 | public Type getType() 45 | { 46 | return type; 47 | } 48 | 49 | @Override 50 | public int hashCode() 51 | { 52 | return Objects.hash(name, type); 53 | } 54 | 55 | @Override 56 | public String toString() 57 | { 58 | return name; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object obj) 63 | { 64 | if (this == obj) { 65 | return true; 66 | } 67 | if (obj == null || getClass() != obj.getClass()) { 68 | return false; 69 | } 70 | GlutenVariableReferenceExpression other = (GlutenVariableReferenceExpression) obj; 71 | return Objects.equals(this.name, other.name) && Objects.equals(this.type, other.type); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /java/src/main/java/io/trino/velox/protocol/SplitAssignmentsMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.velox.protocol; 15 | 16 | import com.fasterxml.jackson.annotation.JsonCreator; 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import io.trino.execution.SplitAssignment; 19 | import io.trino.execution.TaskId; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | public class SplitAssignmentsMessage 25 | { 26 | private final TaskId taskId; 27 | private final List splitAssignments; 28 | 29 | @JsonCreator 30 | public SplitAssignmentsMessage( 31 | @JsonProperty("taskId") TaskId taskId, 32 | @JsonProperty("splitAssignments") List splitAssignments) 33 | { 34 | this.taskId = taskId; 35 | this.splitAssignments = splitAssignments; 36 | } 37 | 38 | public static SplitAssignmentsMessage create(TaskId taskId, List splitAssignments) 39 | { 40 | List glutenSplitAssignments = new ArrayList<>(splitAssignments.size()); 41 | for (SplitAssignment splitAssignment : splitAssignments) { 42 | glutenSplitAssignments.add(GlutenSplitAssignment.create(splitAssignment)); 43 | } 44 | return new SplitAssignmentsMessage(taskId, glutenSplitAssignments); 45 | } 46 | 47 | @JsonProperty 48 | public TaskId getTaskId() 49 | { 50 | return taskId; 51 | } 52 | 53 | @JsonProperty 54 | public List getSplitAssignments() 55 | { 56 | return splitAssignments; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /java/src/test/java/io/trino/gluten/tests/GlutenClient.java: -------------------------------------------------------------------------------- 1 | package io.trino.gluten.tests; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import java.sql.Connection; 18 | import java.sql.DriverManager; 19 | import java.sql.ResultSet; 20 | import java.sql.ResultSetMetaData; 21 | import java.sql.SQLException; 22 | import java.sql.Statement; 23 | import java.util.Properties; 24 | 25 | public class GlutenClient 26 | { 27 | private Connection conn; 28 | 29 | public GlutenClient(String url, Properties properties) 30 | throws SQLException 31 | { 32 | conn = DriverManager.getConnection(url, properties); 33 | } 34 | 35 | public static void main(String[] args) 36 | throws SQLException 37 | { 38 | String url = "jdbc:trino://127.0.0.1:8080/"; 39 | 40 | Properties properties = new Properties(); 41 | properties.setProperty("user", "test"); 42 | 43 | GlutenClient client = new GlutenClient(url, properties); 44 | client.executeQueryAndPrintResult("SELECT * FROM lineitem limit 10"); 45 | 46 | client.close(); 47 | } 48 | 49 | public void executeQueryAndPrintResult(String sql) 50 | throws SQLException 51 | { 52 | Statement stmt = conn.createStatement(); 53 | ResultSet rs = stmt.executeQuery(sql); 54 | ResultSetMetaData rsmd = rs.getMetaData(); 55 | int columnsNumber = rsmd.getColumnCount(); 56 | while (rs.next()) { 57 | for (int i = 1; i <= columnsNumber; i++) { 58 | if (i > 1) { 59 | System.out.print(", "); 60 | } 61 | String columnValue = rs.getString(i); 62 | System.out.print(columnValue + " " + rsmd.getColumnName(i)); 63 | } 64 | System.out.println(""); 65 | } 66 | System.out.println("run query successful! "); 67 | 68 | rs.close(); 69 | stmt.close(); 70 | } 71 | 72 | public void close() 73 | throws SQLException 74 | { 75 | conn.close(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /java/src/test/java/io/trino/jni/TestTrinoBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package io.trino.jni; 16 | 17 | import org.testng.annotations.Test; 18 | 19 | public class TestTrinoBridge 20 | { 21 | @Test 22 | public void testNothing() 23 | { 24 | System.out.println("Test Nothing."); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java/src/test/java/io/trino/jni/TrinoBridgeGetMetrics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package io.trino.jni; 15 | 16 | import io.airlift.json.JsonCodec; 17 | import io.airlift.json.JsonCodecFactory; 18 | import io.trino.execution.TaskStatus; 19 | 20 | public class TrinoBridgeGetMetrics 21 | { 22 | private TrinoBridgeGetMetrics() {} 23 | 24 | static void testTaskStatus(TrinoBridge bridge, long handle) 25 | { 26 | String status = bridge.getTaskStatus(handle, "aaa"); 27 | System.out.println(status); 28 | 29 | JsonCodec codec = new JsonCodecFactory().jsonCodec(TaskStatus.class); 30 | TaskStatus taskStatus = codec.fromJson(status); 31 | 32 | System.out.println(taskStatus.toString()); 33 | } 34 | 35 | public static void main(String[] args) 36 | { 37 | TrinoBridge bridge = new TrinoBridge(); 38 | try { 39 | String configJson = "{\"maxOutputPageBytes\": 1024, \"maxWorkerThreads\": 1, \"maxDriversPerTask\": 1}"; 40 | long handle = bridge.init(configJson, null); 41 | long task1 = bridge.createTestTask(handle, "aaa"); 42 | System.out.println(task1 == 0); 43 | 44 | testTaskStatus(bridge, handle); 45 | 46 | long task2 = bridge.createTestTask(handle, "aaa"); 47 | System.out.println(task2 == 1); 48 | 49 | bridge.close(handle); 50 | } 51 | catch (Error e) { 52 | e.printStackTrace(); 53 | System.out.println(e.toString()); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q1.sql: -------------------------------------------------------------------------------- 1 | 2 | SELECT 3 | l.returnflag, 4 | l.linestatus, 5 | sum(l.quantity) AS sum_qty, 6 | sum(l.extendedprice) AS sum_base_price, 7 | sum(l.extendedprice * (1 - l.discount)) AS sum_disc_price, 8 | sum(l.extendedprice * (1 - l.discount) * (1 + l.tax)) AS sum_charge, 9 | avg(l.quantity) AS avg_qty, 10 | avg(l.extendedprice) AS avg_price, 11 | avg(l.discount) AS avg_disc, 12 | count(*) AS count_order 13 | FROM 14 | "${database}"."${schema}"."${prefix}lineitem" AS l 15 | WHERE 16 | l.shipdate <= DATE '1998-12-01' - INTERVAL '90' DAY 17 | GROUP BY 18 | l.returnflag, 19 | l.linestatus 20 | ORDER BY 21 | l.returnflag, 22 | l.linestatus 23 | 24 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q10.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | c.custkey, 3 | c.name, 4 | sum(l.extendedprice * (1 - l.discount)) AS revenue, 5 | c.acctbal, 6 | n.name, 7 | c.address, 8 | c.phone, 9 | c.comment 10 | FROM 11 | "${database}"."${schema}"."${prefix}lineitem" AS l, 12 | "${database}"."${schema}"."${prefix}orders" AS o, 13 | "${database}"."${schema}"."${prefix}customer" AS c, 14 | "${database}"."${schema}"."${prefix}nation" AS n 15 | WHERE 16 | c.custkey = o.custkey 17 | AND l.orderkey = o.orderkey 18 | AND o.orderdate >= DATE '1993-10-01' 19 | AND o.orderdate < DATE '1993-10-01' + INTERVAL '3' MONTH 20 | AND l.returnflag = 'R' 21 | AND c.nationkey = n.nationkey 22 | GROUP BY 23 | c.custkey, 24 | c.name, 25 | c.acctbal, 26 | c.phone, 27 | n.name, 28 | c.address, 29 | c.comment 30 | ORDER BY 31 | revenue DESC 32 | LIMIT 20 33 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q11.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | ps.partkey, 3 | sum(ps.supplycost*ps.availqty) AS value 4 | FROM 5 | "${database}"."${schema}"."${prefix}partsupp" ps, 6 | "${database}"."${schema}"."${prefix}supplier" s, 7 | "${database}"."${schema}"."${prefix}nation" n 8 | WHERE 9 | ps.suppkey = s.suppkey 10 | AND s.nationkey = n.nationkey 11 | AND n.name = 'GERMANY' 12 | GROUP BY 13 | ps.partkey 14 | HAVING 15 | sum(ps.supplycost*ps.availqty) > ( 16 | SELECT 17 | sum(ps.supplycost*ps.availqty) * 0.0001000000 / ${scale} 18 | FROM 19 | "${database}"."${schema}"."${prefix}partsupp" ps, 20 | "${database}"."${schema}"."${prefix}supplier" s, 21 | "${database}"."${schema}"."${prefix}nation" n 22 | WHERE 23 | ps.suppkey = s.suppkey 24 | AND s.nationkey = n.nationkey 25 | AND n.name = 'GERMANY' 26 | ) 27 | ORDER BY 28 | value DESC, 29 | -- additional column to assure results stability for larger scale factors; this is a deviation from TPC-H specification 30 | ps.partkey ASC 31 | 32 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q12.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | l.shipmode, 3 | sum(CASE 4 | WHEN o.orderpriority = '1-URGENT' 5 | OR o.orderpriority = '2-HIGH' 6 | THEN 1 7 | ELSE 0 8 | END) AS high_line_count, 9 | sum(CASE 10 | WHEN o.orderpriority <> '1-URGENT' 11 | AND o.orderpriority <> '2-HIGH' 12 | THEN 1 13 | ELSE 0 14 | END) AS low_line_count 15 | FROM 16 | "${database}"."${schema}"."${prefix}orders" AS o, 17 | "${database}"."${schema}"."${prefix}lineitem" AS l 18 | WHERE 19 | o.orderkey = l.orderkey 20 | AND l.shipmode IN ('MAIL', 'SHIP') 21 | AND l.commitdate < l.receiptdate 22 | AND l.shipdate < l.commitdate 23 | AND l.receiptdate >= DATE '1994-01-01' 24 | AND l.receiptdate < DATE '1994-01-01' + INTERVAL '1' YEAR 25 | GROUP BY 26 | l.shipmode 27 | ORDER BY 28 | l.shipmode 29 | 30 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q13.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | c_count, 3 | count(*) as custdist 4 | FROM ( 5 | SELECT 6 | c.custkey, 7 | count(o.orderkey) 8 | FROM 9 | "${database}"."${schema}"."${prefix}customer" c 10 | LEFT OUTER JOIN 11 | "${database}"."${schema}"."${prefix}orders" o 12 | ON 13 | c.custkey = o.custkey 14 | AND o.comment NOT LIKE '%special%requests%' 15 | GROUP BY c.custkey 16 | ) AS c_orders (c_custkey, c_count) 17 | GROUP BY 18 | c_count 19 | ORDER BY 20 | custdist DESC, 21 | c_count DESC 22 | 23 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q14.sql: -------------------------------------------------------------------------------- 1 | SELECT 100.00 * sum(CASE 2 | WHEN p.type LIKE 'PROMO%' 3 | THEN l.extendedprice * (1 - l.discount) 4 | ELSE 0 5 | END) / sum(l.extendedprice * (1 - l.discount)) AS promo_revenue 6 | FROM 7 | "${database}"."${schema}"."${prefix}lineitem" AS l, 8 | "${database}"."${schema}"."${prefix}part" AS p 9 | WHERE 10 | l.partkey = p.partkey 11 | AND l.shipdate >= DATE '1995-09-01' 12 | AND l.shipdate < DATE '1995-09-01' + INTERVAL '1' MONTH 13 | 14 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q15.sql: -------------------------------------------------------------------------------- 1 | WITH revenue0 AS ( 2 | SELECT 3 | l.suppkey as supplier_no, 4 | sum(l.extendedprice*(1-l.discount)) as total_revenue 5 | FROM 6 | "${database}"."${schema}"."${prefix}lineitem" l 7 | WHERE 8 | l.shipdate >= DATE '1996-01-01' 9 | AND l.shipdate < DATE '1996-01-01' + INTERVAL '3' MONTH 10 | GROUP BY 11 | l.suppkey 12 | ) 13 | 14 | /* TPC_H Query 15 - Top Supplier */ 15 | SELECT 16 | s.suppkey, 17 | s.name, 18 | s.address, 19 | s.phone, 20 | total_revenue 21 | FROM 22 | "${database}"."${schema}"."${prefix}supplier" s, 23 | revenue0 24 | WHERE 25 | s.suppkey = supplier_no 26 | AND total_revenue = (SELECT max(total_revenue) FROM revenue0) 27 | ORDER BY 28 | s.suppkey 29 | 30 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q16.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | p.brand, 3 | p.type, 4 | p.size, 5 | count(DISTINCT ps.suppkey) AS supplier_cnt 6 | FROM 7 | "${database}"."${schema}"."${prefix}partsupp" AS ps, 8 | "${database}"."${schema}"."${prefix}part" AS p 9 | WHERE 10 | p.partkey = ps.partkey 11 | AND p.brand <> 'Brand#45' 12 | AND p.type NOT LIKE 'MEDIUM POLISHED%' 13 | AND p.size IN (49, 14, 23, 45, 19, 3, 36, 9) 14 | AND ps.suppkey NOT IN ( 15 | SELECT s.suppkey 16 | FROM 17 | "${database}"."${schema}"."${prefix}supplier" AS s 18 | WHERE 19 | s.comment LIKE '%Customer%Complaints%' 20 | ) 21 | GROUP BY 22 | p.brand, 23 | p.type, 24 | p.size 25 | ORDER BY 26 | supplier_cnt DESC, 27 | p.brand, 28 | p.type, 29 | p.size 30 | 31 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q17.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | sum(l.extendedprice)/7.0 as avg_yearly 3 | FROM 4 | "${database}"."${schema}"."${prefix}lineitem" l, 5 | "${database}"."${schema}"."${prefix}part" p 6 | WHERE 7 | p.partkey = l.partkey 8 | AND p.brand = 'Brand#23' 9 | AND p.container = 'MED BOX' 10 | AND l.quantity < ( 11 | SELECT 12 | 0.2*avg(l.quantity) 13 | FROM 14 | "${database}"."${schema}"."${prefix}lineitem" l 15 | WHERE 16 | l.partkey = p.partkey 17 | ) 18 | 19 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q18.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | c.name, 3 | c.custkey, 4 | o.orderkey, 5 | o.orderdate, 6 | o.totalprice, 7 | sum(l.quantity) 8 | FROM 9 | "${database}"."${schema}"."${prefix}customer" AS c, 10 | "${database}"."${schema}"."${prefix}orders" AS o, 11 | "${database}"."${schema}"."${prefix}lineitem" AS l 12 | WHERE 13 | o.orderkey IN ( 14 | SELECT l.orderkey 15 | FROM 16 | "${database}"."${schema}"."${prefix}lineitem" AS l 17 | GROUP BY 18 | l.orderkey 19 | HAVING 20 | sum(l.quantity) > 300 21 | ) 22 | AND c.custkey = o.custkey 23 | AND o.orderkey = l.orderkey 24 | GROUP BY 25 | c.name, 26 | c.custkey, 27 | o.orderkey, 28 | o.orderdate, 29 | o.totalprice 30 | ORDER BY 31 | o.totalprice DESC, 32 | o.orderdate 33 | LIMIT 100 34 | 35 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q19.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | sum(l.extendedprice* (1 - l.discount)) as revenue 3 | FROM 4 | "${database}"."${schema}"."${prefix}lineitem" l, 5 | "${database}"."${schema}"."${prefix}part" p 6 | WHERE 7 | p.partkey = l.partkey 8 | AND 9 | (( 10 | p.brand = 'Brand#12' 11 | AND p.container IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') 12 | AND l.quantity >= 1 13 | AND l.quantity <= 1 + 10 14 | AND p.size BETWEEN 1 AND 5 15 | AND l.shipmode IN ('AIR', 'AIR REG') 16 | AND l.shipinstruct = 'DELIVER IN PERSON' 17 | ) 18 | OR ( 19 | p.brand ='Brand#23' 20 | AND p.container IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') 21 | AND l.quantity >=10 22 | AND l.quantity <=10 + 10 23 | AND p.size BETWEEN 1 AND 10 24 | AND l.shipmode IN ('AIR', 'AIR REG') 25 | AND l.shipinstruct = 'DELIVER IN PERSON' 26 | ) 27 | OR ( 28 | p.brand = 'Brand#34' 29 | AND p.container IN ( 'LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') 30 | AND l.quantity >=20 31 | AND l.quantity <= 20 + 10 32 | AND p.size BETWEEN 1 AND 15 33 | AND l.shipmode IN ('AIR', 'AIR REG') 34 | AND l.shipinstruct = 'DELIVER IN PERSON' 35 | )) 36 | 37 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q2.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | s.acctbal, 3 | s.name, 4 | n.name, 5 | p.partkey, 6 | p.mfgr, 7 | s.address, 8 | s.phone, 9 | s.comment 10 | FROM 11 | "${database}"."${schema}"."${prefix}part" p, 12 | "${database}"."${schema}"."${prefix}supplier" s, 13 | "${database}"."${schema}"."${prefix}partsupp" ps, 14 | "${database}"."${schema}"."${prefix}nation" n, 15 | "${database}"."${schema}"."${prefix}region" r 16 | WHERE 17 | p.partkey = ps.partkey 18 | AND s.suppkey = ps.suppkey 19 | AND p.size = 15 20 | AND p.type like '%BRASS' 21 | AND s.nationkey = n.nationkey 22 | AND n.regionkey = r.regionkey 23 | AND r.name = 'EUROPE' 24 | AND ps.supplycost = ( 25 | SELECT 26 | min(ps.supplycost) 27 | FROM 28 | "${database}"."${schema}"."${prefix}partsupp" ps, 29 | "${database}"."${schema}"."${prefix}supplier" s, 30 | "${database}"."${schema}"."${prefix}nation" n, 31 | "${database}"."${schema}"."${prefix}region" r 32 | WHERE 33 | p.partkey = ps.partkey 34 | AND s.suppkey = ps.suppkey 35 | AND s.nationkey = n.nationkey 36 | AND n.regionkey = r.regionkey 37 | AND r.name = 'EUROPE' 38 | ) 39 | ORDER BY 40 | s.acctbal desc, 41 | n.name, 42 | s.name, 43 | p.partkey 44 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q20.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | s.name, 3 | s.address 4 | FROM 5 | "${database}"."${schema}"."${prefix}supplier" s, 6 | "${database}"."${schema}"."${prefix}nation" n 7 | WHERE 8 | s.suppkey IN ( 9 | SELECT 10 | ps.suppkey 11 | FROM 12 | "${database}"."${schema}"."${prefix}partsupp" ps 13 | WHERE 14 | ps.partkey IN ( 15 | SELECT 16 | p.partkey 17 | FROM 18 | "${database}"."${schema}"."${prefix}part" p 19 | WHERE 20 | p.name like 'forest%' 21 | ) 22 | AND ps.availqty > ( 23 | SELECT 24 | 0.5*sum(l.quantity) 25 | FROM 26 | "${database}"."${schema}"."${prefix}lineitem" l 27 | WHERE 28 | l.partkey = ps.partkey 29 | AND l.suppkey = ps.suppkey 30 | AND l.shipdate >= date('1994-01-01') 31 | AND l.shipdate < date('1994-01-01') + interval '1' YEAR 32 | ) 33 | ) 34 | AND s.nationkey = n.nationkey 35 | AND n.name = 'CANADA' 36 | ORDER BY 37 | s.name 38 | 39 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q21.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | s.name, 3 | count(*) as numwait 4 | FROM 5 | "${database}"."${schema}"."${prefix}supplier" s, 6 | "${database}"."${schema}"."${prefix}lineitem" l1, 7 | "${database}"."${schema}"."${prefix}orders" o, 8 | "${database}"."${schema}"."${prefix}nation" n 9 | WHERE 10 | s.suppkey = l1.suppkey 11 | AND o.orderkey = l1.orderkey 12 | AND o.orderstatus = 'F' 13 | AND l1.receiptdate> l1.commitdate 14 | AND EXISTS ( 15 | SELECT 16 | * 17 | FROM 18 | "${database}"."${schema}"."${prefix}lineitem" l2 19 | WHERE 20 | l2.orderkey = l1.orderkey 21 | AND l2.suppkey <> l1.suppkey 22 | ) 23 | AND NOT EXISTS ( 24 | SELECT 25 | * 26 | FROM 27 | "${database}"."${schema}"."${prefix}lineitem" l3 28 | WHERE 29 | l3.orderkey = l1.orderkey 30 | AND l3.suppkey <> l1.suppkey 31 | AND l3.receiptdate > l3.commitdate 32 | ) 33 | AND s.nationkey = n.nationkey 34 | AND n.name = 'SAUDI ARABIA' 35 | GROUP BY 36 | s.name 37 | ORDER BY 38 | numwait DESC, 39 | s.name 40 | LIMIT 41 | 100 42 | 43 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q22.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | cntrycode, 3 | count(*) AS numcust, 4 | sum(acctbal) AS totacctbal 5 | FROM 6 | ( 7 | SELECT 8 | substr(c.phone,1,2) AS cntrycode, 9 | c.acctbal 10 | FROM 11 | "${database}"."${schema}"."${prefix}customer" c 12 | WHERE 13 | substr(c.phone,1,2) IN ('13', '31', '23', '29', '30', '18', '17') 14 | AND c.acctbal > ( 15 | SELECT 16 | avg(c.acctbal) 17 | FROM 18 | "${database}"."${schema}"."${prefix}customer" c 19 | WHERE 20 | c.acctbal > 0.00 21 | AND substr(c.phone,1,2) IN ('13', '31', '23', '29', '30', '18', '17') 22 | ) 23 | AND NOT EXISTS ( 24 | SELECT 25 | * 26 | FROM 27 | "${database}"."${schema}"."${prefix}orders" o 28 | WHERE 29 | o.custkey = c.custkey 30 | ) 31 | ) AS custsale 32 | GROUP BY 33 | cntrycode 34 | ORDER BY 35 | cntrycode 36 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q3.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | l.orderkey, 3 | sum(l.extendedprice * (1 - l.discount)) AS revenue, 4 | o.orderdate, 5 | o.shippriority 6 | FROM 7 | "${database}"."${schema}"."${prefix}customer" AS c, 8 | "${database}"."${schema}"."${prefix}orders" AS o, 9 | "${database}"."${schema}"."${prefix}lineitem" AS l 10 | WHERE 11 | c.mktsegment = 'BUILDING' 12 | AND c.custkey = o.custkey 13 | AND l.orderkey = o.orderkey 14 | AND o.orderdate < DATE '1995-03-15' 15 | AND l.shipdate > DATE '1995-03-15' 16 | GROUP BY 17 | l.orderkey, 18 | o.orderdate, 19 | o.shippriority 20 | ORDER BY 21 | revenue DESC, 22 | o.orderdate 23 | LIMIT 10 24 | 25 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q4.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | o.orderpriority, 3 | count(*) AS order_count 4 | FROM 5 | "${database}"."${schema}"."${prefix}orders" o 6 | WHERE 7 | o.orderdate >= DATE '1993-07-01' 8 | AND o.orderdate < DATE '1993-07-01' + INTERVAL '3' MONTH 9 | AND EXISTS ( 10 | SELECT 11 | * 12 | FROM 13 | "${database}"."${schema}"."${prefix}lineitem" l 14 | WHERE 15 | l.orderkey = o.orderkey 16 | AND l.commitdate < l.receiptdate 17 | ) 18 | GROUP BY 19 | o.orderpriority 20 | ORDER BY 21 | o.orderpriority 22 | 23 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q5.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | n.name, 3 | sum(l.extendedprice * (1 - l.discount)) AS revenue 4 | FROM 5 | "${database}"."${schema}"."${prefix}customer" AS c, 6 | "${database}"."${schema}"."${prefix}orders" AS o, 7 | "${database}"."${schema}"."${prefix}lineitem" AS l, 8 | "${database}"."${schema}"."${prefix}supplier" AS s, 9 | "${database}"."${schema}"."${prefix}nation" AS n, 10 | "${database}"."${schema}"."${prefix}region" AS r 11 | WHERE 12 | c.custkey = o.custkey 13 | AND l.orderkey = o.orderkey 14 | AND l.suppkey = s.suppkey 15 | AND c.nationkey = s.nationkey 16 | AND s.nationkey = n.nationkey 17 | AND n.regionkey = r.regionkey 18 | AND r.name = 'ASIA' 19 | AND o.orderdate >= DATE '1994-01-01' 20 | AND o.orderdate < DATE '1994-01-01' + INTERVAL '1' YEAR 21 | GROUP BY 22 | n.name 23 | ORDER BY 24 | revenue DESC 25 | 26 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q6.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | sum(l.extendedprice*l.discount) AS revenue 3 | FROM 4 | "${database}"."${schema}"."${prefix}lineitem" l 5 | WHERE 6 | l.shipdate >= DATE '1994-01-01' 7 | AND l.shipdate < DATE '1994-01-01' + INTERVAL '1' YEAR 8 | AND l.discount BETWEEN .06 - 0.01 AND .06 + 0.01 9 | AND l.quantity < 24 10 | 11 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q7.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | supp_nation, 3 | cust_nation, 4 | l_year, 5 | sum(volume) AS revenue 6 | FROM ( 7 | SELECT 8 | n1.name AS supp_nation, 9 | n2.name AS cust_nation, 10 | extract(YEAR FROM l.shipdate) AS l_year, 11 | l.extendedprice * (1 - l.discount) AS volume 12 | FROM 13 | "${database}"."${schema}"."${prefix}supplier" AS s, 14 | "${database}"."${schema}"."${prefix}lineitem" AS l, 15 | "${database}"."${schema}"."${prefix}orders" AS o, 16 | "${database}"."${schema}"."${prefix}customer" AS c, 17 | "${database}"."${schema}"."${prefix}nation" AS n1, 18 | "${database}"."${schema}"."${prefix}nation" AS n2 19 | WHERE 20 | s.suppkey = l.suppkey 21 | AND o.orderkey = l.orderkey 22 | AND c.custkey = o.custkey 23 | AND s.nationkey = n1.nationkey 24 | AND c.nationkey = n2.nationkey 25 | AND ( 26 | (n1.name = 'FRANCE' AND n2.name = 'GERMANY') 27 | OR (n1.name = 'GERMANY' AND n2.name = 'FRANCE') 28 | ) 29 | AND l.shipdate BETWEEN DATE '1995-01-01' AND DATE '1996-12-31' 30 | ) AS shipping 31 | GROUP BY 32 | supp_nation, 33 | cust_nation, 34 | l_year 35 | ORDER BY 36 | supp_nation, 37 | cust_nation, 38 | l_year 39 | 40 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q8.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | o_year, 3 | sum(CASE 4 | WHEN nation = 'BRAZIL' 5 | THEN volume 6 | ELSE 0 7 | END) / sum(volume) AS mkt_share 8 | FROM ( 9 | SELECT 10 | extract(YEAR FROM o.orderdate) AS o_year, 11 | l.extendedprice * (1 - l.discount) AS volume, 12 | n2.name AS nation 13 | FROM 14 | "${database}"."${schema}"."${prefix}part" AS p, 15 | "${database}"."${schema}"."${prefix}supplier" AS s, 16 | "${database}"."${schema}"."${prefix}lineitem" AS l, 17 | "${database}"."${schema}"."${prefix}orders" AS o, 18 | "${database}"."${schema}"."${prefix}customer" AS c, 19 | "${database}"."${schema}"."${prefix}nation" AS n1, 20 | "${database}"."${schema}"."${prefix}nation" AS n2, 21 | "${database}"."${schema}"."${prefix}region" AS r 22 | WHERE 23 | p.partkey = l.partkey 24 | AND s.suppkey = l.suppkey 25 | AND l.orderkey = o.orderkey 26 | AND o.custkey = c.custkey 27 | AND c.nationkey = n1.nationkey 28 | AND n1.regionkey = r.regionkey 29 | AND r.name = 'AMERICA' 30 | AND s.nationkey = n2.nationkey 31 | AND o.orderdate BETWEEN DATE '1995-01-01' AND DATE '1996-12-31' 32 | AND p.type = 'ECONOMY ANODIZED STEEL' 33 | ) AS all_nations 34 | GROUP BY 35 | o_year 36 | ORDER BY 37 | o_year 38 | 39 | -------------------------------------------------------------------------------- /java/src/test/resources/io/trino/gluten/tests/tpch/q9.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | nation, 3 | o_year, 4 | sum(amount) AS sum_profit 5 | FROM ( 6 | SELECT 7 | n.name AS nation, 8 | extract(YEAR FROM o.orderdate) AS o_year, 9 | l.extendedprice * (1 - l.discount) - ps.supplycost * l.quantity AS amount 10 | FROM 11 | "${database}"."${schema}"."${prefix}part" AS p, 12 | "${database}"."${schema}"."${prefix}supplier" AS s, 13 | "${database}"."${schema}"."${prefix}lineitem" AS l, 14 | "${database}"."${schema}"."${prefix}partsupp" AS ps, 15 | "${database}"."${schema}"."${prefix}orders" AS o, 16 | "${database}"."${schema}"."${prefix}nation" AS n 17 | WHERE 18 | s.suppkey = l.suppkey 19 | AND ps.suppkey = l.suppkey 20 | AND ps.partkey = l.partkey 21 | AND p.partkey = l.partkey 22 | AND o.orderkey = l.orderkey 23 | AND s.nationkey = n.nationkey 24 | AND p.name LIKE '%green%' 25 | ) AS profit 26 | GROUP BY 27 | nation, 28 | o_year 29 | ORDER BY 30 | nation, 31 | o_year DESC 32 | -------------------------------------------------------------------------------- /migrate.sh: -------------------------------------------------------------------------------- 1 | first_commit=38ed246f28 2 | last_commit=217aae49e2 3 | git checkout $last_commit 4 | 5 | commit_msg=`git log $first_commit..$last_commit --pretty=format:"%s" ` 6 | git checkout --orphan dev_module 7 | git reset 8 | git diff --name-only $first_commit $last_commit > diff_files 9 | git add trino-cpp 10 | git add .mvn .gitignore .gitmodules .java-version LICENSE migrate.sh 11 | mkdir trino-cpp-plugin 12 | files=`cat diff_files|grep java|grep -v trino-cpp|grep -v testing` 13 | 14 | # echo $files|cut -d'/' -f3-|awk '{print "rsync -Rav --relative "$0" trino-cpp-plugin/"}'|sh 15 | 16 | cat diff_files|grep java|grep -v trino-cpp|grep -v testing| while read -r file; do 17 | to_path=`echo $file|cut -d'/' -f3-|rev|cut -d'/' -f2-|rev` 18 | mkdir -p trino-cpp-plugin/$to_path 19 | cp --path $file trino-cpp-plugin/$to_path 20 | done 21 | # cp $file trino-cpp-plugin/$to_path 22 | 23 | git add trino-cpp-plugin 24 | git clean -f -d 25 | git commit -m "migrate to new branch, previous commit log: " -m "$commit_msg" 26 | -------------------------------------------------------------------------------- /scripts/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM centos:8 2 | 3 | # to avoid "No URLs in mirrorlist" 4 | RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* 5 | RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* 6 | 7 | ADD Gluten-Trino /opt/Gluten-Trino 8 | 9 | RUN /opt/Gluten-Trino/cpp/scripts/setup-velox-centos8.sh 10 | RUN rm -rf /opt/Gluten-Trino/cpp/thirdparty 11 | RUN dnf install -y jq 12 | 13 | RUN echo "source /opt/rh/gcc-toolset-9/enable" >> ~/.bashrc 14 | 15 | RUN wget "https://cdn.azul.com/zulu/bin/zulu17.44.53-ca-jdk17.0.8.1-linux_x64.tar.gz" 16 | RUN tar zxf zulu17.44.53-ca-jdk17.0.8.1-linux_x64.tar.gz 17 | RUN rm -rf zulu17.44.53-ca-jdk17.0.8.1-linux_x64.tar.gz 18 | 19 | ENV JAVA_HOME=/zulu17.44.53-ca-jdk17.0.8.1-linux_x64 20 | ENV PATH=$PATH:$JAVA_HOME/bin 21 | 22 | RUN wget "https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz" 23 | RUN tar zxf apache-maven-3.9.5-bin.tar.gz 24 | RUN rm -rf apache-maven-3.9.5-bin.tar.gz 25 | 26 | ENV MAVEN_HOME=/apache-maven-3.9.5 27 | ENV PATH=$PATH:$MAVEN_HOME/bin 28 | 29 | RUN /opt/Gluten-Trino/scripts/build_all.sh 30 | 31 | RUN mv /opt/Gluten-Trino/release /Gluten-Trino 32 | ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/Gluten-Trino 33 | RUN rm -rf /opt/Gluten-Trino 34 | 35 | WORKDIR / 36 | RUN wget "https://repo1.maven.org/maven2/io/trino/trino-server/411/trino-server-411.tar.gz" 37 | RUN tar zxf trino-server-411.tar.gz 38 | RUN rm -rf trino-server-411.tar.gz 39 | 40 | RUN ln -s /usr/bin/python3 /usr/bin/python 41 | 42 | RUN sed -i 's/classpath = pathjoin/classpath = \"\/Gluten-Trino\/Gluten-Trino-411.jar\:\" + pathjoin/g' /trino-server-411/bin/launcher.py 43 | -------------------------------------------------------------------------------- /scripts/build_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | set -e 5 | set -o pipefail 6 | 7 | if [[ -f /opt/rh/gcc-toolset-9/enable ]]; then 8 | # It's expected to use gcc 9 to build GlutenTrino. 9 | source /opt/rh/gcc-toolset-9/enable 10 | fi 11 | 12 | GLUTEN_TRINO_HOME="$(cd "`dirname "$0"`"; cd ..; pwd)" 13 | 14 | if ! git -v > /dev/null ; then 15 | dnf install -y git 16 | fi 17 | 18 | pushd ${GLUTEN_TRINO_HOME} 19 | git clone https://github.com/trinodb/trino.git -b 411 --depth=1 20 | export TRINO_HOME=${GLUTEN_TRINO_HOME}/trino 21 | popd 22 | 23 | # build cpp 24 | cd ${GLUTEN_TRINO_HOME}/cpp 25 | mkdir build && cd build 26 | cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja 27 | ninja 28 | 29 | # build java 30 | cd ${GLUTEN_TRINO_HOME}/java 31 | mvn clean package -DskipTests=True -Dair.check.skip-duplicate-finder=True 32 | 33 | # make distribution 34 | pushd ${GLUTEN_TRINO_HOME} 35 | mkdir release && cd release 36 | cp ${GLUTEN_TRINO_HOME}/cpp/build/src/libgluten_trino.so . 37 | cp ${GLUTEN_TRINO_HOME}/java/target/Gluten-Trino-411.jar . 38 | popd 39 | --------------------------------------------------------------------------------