HCatalog IO
HCatalogIO
是一個轉換,用於讀取和寫入到 HCatalog 管理的來源的資料。
使用 HCatalogIO 讀取
若要設定 HCatalog 來源,您必須指定中繼存放區 URI 和資料表名稱。其他選用參數是資料庫和篩選器。
例如
Map<String, String> configProperties = new HashMap<String, String>();
configProperties.put("hive.metastore.uris","thrift://metastore-host:port");
pipeline
.apply(HCatalogIO.read()
.withConfigProperties(configProperties)
.withDatabase("default") //optional, assumes default if none specified
.withTable("employee")
.withFilter(filterString)) //optional, may be specified if the table is partitioned
使用 HCatalogIO 寫入
若要設定 HCatalog
接收器,您必須指定中繼存放區 URI 和資料表名稱。其他選用參數是資料庫、分割區和批次大小。目標資料表應該預先存在,因為如果遺失,轉換將不會建立新資料表。
例如
Map<String, String> configProperties = new HashMap<String, String>();
configProperties.put("hive.metastore.uris","thrift://metastore-host:port");
pipeline
.apply(...)
.apply(HCatalogIO.write()
.withConfigProperties(configProperties)
.withDatabase("default") //optional, assumes default if none specified
.withTable("employee")
.withPartition(partitionValues) //optional, may be specified if the table is partitioned
.withBatchSize(1024L)) //optional, assumes a default batch size of 1024 if none specified
使用舊版 HCatalog (1.x)
HCatalogIO
是針對 Apache HCatalog 2 版和更新版本建置的,並且無法直接用於舊版本的 HCatalog。以下說明使用 Hive 1.1 的變通方法。
在您建立的 Uber JAR 中包含以下 Hive 1.2 JAR。1.2 JAR 提供 Beam 所需的方法,同時與 Hive 1.1 保持相容性。
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-hcatalog</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hive.hcatalog</groupId>
<artifactId>hive-hcatalog-core</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-metastore</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-common</artifactId>
<version>1.2</version>
</dependency>
僅重新定位以下 Hive 套件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<relocations>
<!-- Important: Do not relocate org.apache.hadoop.hive -->
<relocation>
<pattern>org.apache.hadoop.hive.conf</pattern>
<shadedPattern>h12.org.apache.hadoop.hive.conf</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.hadoop.hive.ql</pattern>
<shadedPattern>h12.org.apache.hadoop.hive.ql</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.hadoop.hive.metastore</pattern>
<shadedPattern>h12.org.apache.hadoop.hive.metastore</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
這已測試過,可以使用 Beam 2.4.0 在 Cloudera CDH 5.12.2 管理的環境中,使用 Spark 2.3 / YARN 執行,讀取以 SequenceFile 和 ORCFile 檔案支援的資料表。
上次更新於 2024/10/31
您是否找到您要尋找的所有內容?
這些內容是否有用且清晰?您是否想變更任何內容?請告訴我們!