GitHub user alberttwong closed a discussion: End to End xtable to Trino query 
with source Hudi and target Iceberg and Delta Lake with HMS and S3

Using openjdk 11, spark 3.4, hive 2.3.10, hadoop 2.10.2

Here is the PR - xtable demo on s3 with documentation. 
https://github.com/apache/incubator-xtable/pull/459 and 
https://github.com/alberttwong/incubator-xtable/tree/main/demo-s3


------- HISTORY

Look the xtable docker demo at https://xtable.apache.org/docs/demo/docker

list of versions to use with hudi 0.14.1 at 
https://github.com/apache/hudi/blob/release-0.14.1/pom.xml

1. added minio container images to provide an object store 
2. changed HMS image to use the Starburst HMS image because Starburst has the 
S3 libraries already built in to the image. 
3. built a custom spark 3.4 container image based on JDK 11 with hadoop 2.10.2 
and hive 2.3.10 (can't use 2.3.1 due to hive 2.3.1 bug) installed. Available at 
https://hub.docker.com/r/atwong/openjdk-11-spark-3.4-hive-2.3.10-hadoop-2.10.2 
if you dont' want to build it.
4. git clone hudi and compile mvn with JDK 8 so you can get the hudi-hive-sync 
jars (you can skip this through hudi-hive-sync-bundle on mvnrepository.com)
5. adding missing libraries to run run_sync_tool.sh.    
https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3, 
https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-aws, 
https://mvnrepository.com/artifact/com.esotericsoftware/kryo-shaded/4.0.2, 
https://mvnrepository.com/artifact/org.apache.parquet/parquet-avro, 
https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client
6. modifications to iceberg, hudi and delta Trino catalog configurations to 
support S3 bucket lookups
7. added core-site.xml to inject parameters to xtable and modified 
/etc/hadoop/core-site.xml to jnject parameters to hudi-hive-sync tool
8. Modified pyspark demo script to include S3 configs

What works so far
1. if I create the hudi 0.14.1 files in S3 with hms sync in the spark config, I 
can skip the registering hudi files to HMS
2. able to use xtable to sync from hudi to iceberg to delta
3. able to query hudi, iceberg and delta

What doesn't work.  How far am I in the process
1. created hudi 0.14.1 files in S3
2. stuck on registering hudi files in S3 to metastore.


Running
```
./run_sync_tool.sh  \
--metastore-uris 'thrift://hive-metastore:9083' \
--partitioned-by city \
--base-path 's3a://warehouse/people' \
--database hudi_db \
--table people \
--sync-mode hms 
```

pyspark
```
from pyspark.sql.types import *
from pyspark import SparkContext
from pyspark.sql import SparkSession
import os

# initialize the bucket
database_name = "hudi_db"
table_name = "people"
base_path = "s3a://warehouse/"

records = [
   (1, 'John', 25, 'NYC', '2023-09-28 00:00:00'),
   (2, 'Emily', 30, 'SFO', '2023-09-28 00:00:00'),
   (3, 'Michael', 35, 'ORD', '2023-09-28 00:00:00'),
   (4, 'Andrew', 40, 'NYC', '2023-10-28 00:00:00'),
   (5, 'Bob', 28, 'SEA', '2023-09-23 00:00:00'),
   (6, 'Charlie', 31, 'DFW', '2023-08-29 00:00:00')
]

schema = StructType([
   StructField("id", IntegerType(), True),
   StructField("name", StringType(), True),
   StructField("age", IntegerType(), True),
   StructField("city", StringType(), True),
   StructField("create_ts", StringType(), True)
])

spark = SparkSession.builder.getOrCreate()

df = spark.createDataFrame(records, schema)

hudi_options = {
#   'hoodie.datasource.hive_sync.enable': 'true',
#   'hoodie.datasource.hive_sync.mode': 'hms',
#   'hoodie.datasource.hive_sync.database': database_name,
#   'hoodie.datasource.hive_sync.table': table_name,
#   'hoodie.datasource.hive_sync.metastore.uris': 
'thrift://hive-metastore:9083',
   'hoodie.table.name': table_name,
   'hoodie.datasource.write.partitionpath.field': 'city',
   'hoodie.datasource.write.hive_style_partitioning': 'true'

}

(
   df.write
   .format("hudi")
   .options(**hudi_options)
   .mode('overwrite')
   .save(f"{base_path}/{table_name}")
)
```

commands modified from the docker demo
```
pyspark --packages 
com.amazonaws:aws-java-sdk-s3:1.12.661,org.apache.hadoop:hadoop-aws:3.3.1,org.apache.hudi:hudi-spark3.4-bundle_2.12:0.14.1
   --conf "spark.serializer=org.apache.spark.serializer.KryoSerializer"   
--conf 
"spark.sql.catalog.spark_catalog=org.apache.spark.sql.hudi.catalog.HoodieCatalog"
   --conf 
"spark.sql.extensions=org.apache.spark.sql.hudi.HoodieSparkSessionExtension" 

export AWS_SECRET_ACCESS_KEY=password
export AWS_ACCESS_KEY_ID=admin
export ENDPOINT=http://minio:9000
export AWS_REGION=us-east-1
java -jar xtable-utilities-0.1.0-SNAPSHOT-bundled.jar --datasetConfig 
xtable_hudi.yaml -p core-site.xml


cd /opt/hudi/hudi-sync/hudi-hive-sync

./run_sync_tool.sh  \
--metastore-uris 'thrift://hive-metastore:9083' \
--partitioned-by city \
--base-path 's3a://warehouse/people' \
--database hudi_db \
--table people \
--sync-mode hms 


spark-sql --packages 
com.amazonaws:aws-java-sdk-s3:1.12.661,org.apache.hadoop:hadoop-aws:3.3.1,org.apache.spark:spark-hadoop-cloud_2.12:3.2.0,io.delta:delta-core_2.12:2.4.0
 \
--conf "spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension" \
--conf 
"spark.sql.catalog.spark_catalog=org.apache.spark.sql.delta.catalog.DeltaCatalog"
 \
--conf "spark.sql.catalogImplementation=hive"

CREATE SCHEMA delta_db LOCATION 's3a://warehouse/';

CREATE TABLE delta_db.people USING DELTA LOCATION 's3a://warehouse/people';

spark-sql --packages 
com.amazonaws:aws-java-sdk-s3:1.12.661,org.apache.hadoop:hadoop-aws:3.3.1,org.apache.iceberg:iceberg-spark-runtime-3.4_2.12:1.5.2
 \
--conf 
"spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions"
 \
--conf 
"spark.sql.catalog.spark_catalog=org.apache.iceberg.spark.SparkSessionCatalog" \
--conf "spark.sql.catalog.spark_catalog.type=hive" \
--conf "spark.sql.catalog.hive_prod=org.apache.iceberg.spark.SparkCatalog" \
--conf "spark.sql.catalog.hive_prod.type=hive"

CREATE SCHEMA iceberg_db;

CALL hive_prod.system.register_table(
   table => 'hive_prod.iceberg_db.people',
   metadata_file => 's3a://warehouse/people/metadata/v2.metadata.json'
);

select * from hudi.hudi_db.people;
select * from delta.delta_db.people;
select * from iceberg.iceberg_db.people;
```

for Hadoop 2.10.2.  Here is the modified  pyspark to create hudi files with AWS 
hadoop 2.10.2 
```
pyspark --packages 
com.amazonaws:aws-java-sdk-s3:1.11.271,org.apache.hadoop:hadoop-client:2.10.2,org.apache.hadoop:hadoop-aws:2.10.2,org.apache.hudi:hudi-spark3.4-bundle_2.12:0.14.1
   --conf "spark.serializer=org.apache.spark.serializer.KryoSerializer"   
--conf 
"spark.sql.catalog.spark_catalog=org.apache.spark.sql.hudi.catalog.HoodieCatalog"
   --conf 
"spark.sql.extensions=org.apache.spark.sql.hudi.HoodieSparkSessionExtension" 
--conf 
"spark.hadoop.fs.s3a.aws.credentials.provider=org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider"

export AWS_SECRET_ACCESS_KEY=password
export AWS_ACCESS_KEY_ID=admin
export ENDPOINT=http://minio:9000
export AWS_REGION=us-east-1
cd /opt/xtable/jars/; java -jar xtable-utilities-0.1.0-SNAPSHOT-bundled.jar 
--datasetConfig xtable_hudi.yaml -p core-site.xml


pyspark --packages 
org.apache.parquet:parquet-avro:1.10.1,com.esotericsoftware:kryo-shaded:4.0.2

pyspark --packages 
org.apache.hudi:hudi-hive-sync:0.14.1,com.amazonaws:aws-java-sdk-s3:1.11.271,org.apache.hadoop:hadoop-client:2.10.2,org.apache.hadoop:hadoop-aws:2.10.2,org.apache.parquet:parquet-avro:1.10.1,com.esotericsoftware:kryo-shaded:4.0.2

pyspark --packages 
org.apache.hudi:hudi-hive-sync-bundle:0.14.1,com.amazonaws:aws-java-sdk-s3:1.11.271,org.apache.hadoop:hadoop-client:2.10.2,org.apache.hadoop:hadoop-aws:2.10.2

rm -Rf /opt/hudi/packaging/;  cp -R /opt/xtable/jars/packaging/ /opt/hudi/


vi /opt/hudi/hudi-sync/hudi-hive-sync/run_sync_tool.sh
~/.ivy2/jars/*:

vi /hadoop/etc/hadoop/core-site.xml 

cd /opt/hudi/hudi-sync/hudi-hive-sync
./run_sync_tool.sh  \
--metastore-uris 'thrift://hive-metastore:9083' \
--partitioned-by city \
--base-path 's3a://warehouse/people' \
--database hudi_db \
--table people \
--sync-mode hms 

vi /etc/trino/catalog

spark-sql --packages 
com.amazonaws:aws-java-sdk-s3:1.11.271,org.apache.hadoop:hadoop-aws:2.10.2,io.delta:delta-core_2.12:2.4.0
 \
--conf "spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension" \
--conf 
"spark.sql.catalog.spark_catalog=org.apache.spark.sql.delta.catalog.DeltaCatalog"
 \
--conf "spark.sql.catalogImplementation=hive" \
--conf 
"spark.hadoop.fs.s3a.aws.credentials.provider=org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider"

CREATE SCHEMA delta_db LOCATION 's3a://warehouse/';

CREATE TABLE delta_db.people USING DELTA LOCATION 's3a://warehouse/people';

spark-sql --packages 
com.amazonaws:aws-java-sdk-s3:1.11.271,org.apache.hadoop:hadoop-aws:2.10.2,org.apache.iceberg:iceberg-spark-runtime-3.4_2.12:1.5.2
 \
--conf 
"spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions"
 \
--conf 
"spark.sql.catalog.spark_catalog=org.apache.iceberg.spark.SparkSessionCatalog" \
--conf "spark.sql.catalog.spark_catalog.type=hive" \
--conf "spark.sql.catalog.hive_prod=org.apache.iceberg.spark.SparkCatalog" \
--conf "spark.sql.catalog.hive_prod.type=hive" \
--conf 
"spark.hadoop.fs.s3a.aws.credentials.provider=org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider"

CREATE SCHEMA iceberg_db;

CALL hive_prod.system.register_table(
   table => 'hive_prod.iceberg_db.people',
   metadata_file => 's3a://warehouse/people/metadata/v2.metadata.json'
);

select * from hudi.hudi_db.people;
select * from delta.delta_db.people;
select * from iceberg.iceberg_db.people;
```

GitHub link: https://github.com/apache/incubator-xtable/discussions/457

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]

Reply via email to