Trino is an open source distributed SQL query engine for running interactive analytic queries. This topic describes how to use JindoSDK with Trino to query data stored in OSS-HDFS.
Prerequisites
For example, to use Elastic Compute Service (ECS) as your deployment environment, you will need to create an instance.
A Hadoop environment is created. For more information about how to install Hadoop, see Step 2: Set up a Hadoop runtime environment.
Trino is deployed. For more information, visit Deploying Trino.
OSS-HDFS is enabled for a bucket and access permissions on OSS-HDFS are granted. For more information, see Enable OSS-HDFS service.
Procedure
-
Connect to the ECS instance. For more information, see Connect to an ECS instance.
Configure JindoSDK.
Download the latest version of the JindoSDK JAR package. To download JindoSDK, visit GitHub.
Decompress the JindoSDK JAR package.
The following sample code provides an example on how to decompress a package named
jindosdk-x.x.x-linux.tar.gz. If you use another version of JindoSDK, replace the package name with the name of the corresponding JAR package.tar zxvf jindosdk-x.x.x-linux.tar.gzNotex.x.x indicates the version number of the JindoSDK JAR package.
Install the downloaded JindoSDK JAR package to the path specified by classpath.
cp jindosdk-x.x.x-linux/lib/*.jar $Trino_HOME/plugin/hive-hadoop2/
Configure the implementation class of OSS-HDFS and specify the AccessKey pair that you want to use to access the bucket.
Configure the implementation class of OSS-HDFS in the Hadoop configuration file named core-site.xml on all Trino nodes.
<configuration> <property> <name>fs.AbstractFileSystem.oss.impl</name> <value>com.aliyun.jindodata.oss.JindoOSS</value> </property> <property> <name>fs.oss.impl</name> <value>com.aliyun.jindodata.oss.JindoOssFileSystem</value> </property> </configuration>In the core-site.xml file on all Trino nodes, specify the AccessKey ID and AccessKey secret that you want to use to access the bucket for which OSS-HDFS is enabled.
<configuration> <property> <name>fs.oss.accessKeyId</name> <value>LTAI********</value> </property> <property> <name>fs.oss.accessKeySecret</name> <value>KZo1********</value> </property> </configuration>
Configure the endpoint of OSS-HDFS.
You must specify the endpoint of OSS-HDFS if you want to use OSS-HDFS to access buckets in Object Storage Service (OSS). We recommend that you configure the path that is used to access OSS-HDFS in the
oss://{yourBucketName}.{yourBucketEndpoint}/{path}format. Example:oss://examplebucket.cn-shanghai.oss-dls.aliyuncs.com/exampleobject.txt. After you configure the access path, JindoSDK calls the corresponding OSS-HDFS operation based on the specified endpoint in the access path.You can also configure the endpoint of OSS-HDFS by using other methods. The endpoints that are configured by using different methods have different priorities. For more information, see Quick start: Connect a non-EMR cluster to the OSS-HDFS service.
ImportantAfter you complete the preceding configurations, you must restart Trino for the configurations to take effect.
Query data stored in OSS-HDFS
In the following example, HiveCatalog is used. You can use Trino to create a schema for OSS and execute SQL statements to query the data that is stored in OSS-HDFS. You must install and deploy JindoSDK in the Hive service because Trino uses Hive Metastore as a dependency. For more information, see Use JindoSDK with Hive to process data stored in OSS-HDFS.
Log on to the Trino console.
trino --server <Trino_server_address>:<Trino_server_port> --catalog hiveCreate a schema for OSS.
create schema testDB with (location='oss://{yourBucketName}.{yourBucketEndpoint}/{schema_dir}');Use the schema.
use testDB;Create a table.
create table tbl (key int, val int);Insert data into the table.
insert into tbl values (1,666);Query data in the table.
select * from tbl;