-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add support to redirect table reads from Hive to Iceberg #10173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.plugin.hive; | ||
|
|
||
| import io.trino.plugin.hive.metastore.Table; | ||
| import io.trino.spi.connector.CatalogSchemaTableName; | ||
| import io.trino.spi.connector.ConnectorSession; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import static io.trino.plugin.hive.HiveSessionProperties.getIcebergCatalogName; | ||
| import static io.trino.plugin.hive.util.HiveUtil.isIcebergTable; | ||
|
|
||
| public class DefaultHiveTableRedirectionsProvider | ||
| implements HiveTableRedirectionsProvider | ||
| { | ||
| @Override | ||
| public Optional<CatalogSchemaTableName> redirectTable(ConnectorSession session, Table table) | ||
| { | ||
| Optional<String> targetCatalogName = getIcebergCatalogName(session); | ||
| if (targetCatalogName.isEmpty()) { | ||
| return Optional.empty(); | ||
| } | ||
| if (isIcebergTable(table)) { | ||
| return targetCatalogName.map(catalog -> new CatalogSchemaTableName(catalog, table.getSchemaTableName())); | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,7 +39,6 @@ | |||||||||||||||||
| import io.trino.spi.TrinoException; | ||||||||||||||||||
| import io.trino.spi.connector.ConnectorSession; | ||||||||||||||||||
| import io.trino.spi.connector.SortOrder; | ||||||||||||||||||
| import io.trino.spi.session.PropertyMetadata; | ||||||||||||||||||
| import io.trino.spi.type.Type; | ||||||||||||||||||
| import io.trino.spi.type.TypeManager; | ||||||||||||||||||
| import org.apache.hadoop.conf.Configuration; | ||||||||||||||||||
|
|
@@ -62,6 +61,7 @@ | |||||||||||||||||
| import java.util.HashSet; | ||||||||||||||||||
| import java.util.List; | ||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||
| import java.util.Map.Entry; | ||||||||||||||||||
| import java.util.Optional; | ||||||||||||||||||
| import java.util.OptionalInt; | ||||||||||||||||||
| import java.util.Properties; | ||||||||||||||||||
|
|
@@ -72,6 +72,7 @@ | |||||||||||||||||
| import static com.google.common.base.Preconditions.checkArgument; | ||||||||||||||||||
| import static com.google.common.collect.ImmutableList.toImmutableList; | ||||||||||||||||||
| import static com.google.common.collect.ImmutableMap.toImmutableMap; | ||||||||||||||||||
| import static com.google.common.collect.Maps.immutableEntry; | ||||||||||||||||||
| import static io.trino.plugin.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR; | ||||||||||||||||||
| import static io.trino.plugin.hive.HiveErrorCode.HIVE_INVALID_METADATA; | ||||||||||||||||||
| import static io.trino.plugin.hive.HiveErrorCode.HIVE_PARTITION_READ_ONLY; | ||||||||||||||||||
|
|
@@ -256,8 +257,12 @@ public HiveWriterFactory( | |||||||||||||||||
|
|
||||||||||||||||||
| requireNonNull(hiveSessionProperties, "hiveSessionProperties is null"); | ||||||||||||||||||
| this.sessionProperties = hiveSessionProperties.getSessionProperties().stream() | ||||||||||||||||||
| .collect(toImmutableMap(PropertyMetadata::getName, | ||||||||||||||||||
| entry -> session.getProperty(entry.getName(), entry.getJavaType()).toString())); | ||||||||||||||||||
| .map(propertyMetadata -> immutableEntry( | ||||||||||||||||||
| propertyMetadata.getName(), | ||||||||||||||||||
| session.getProperty(propertyMetadata.getName(), propertyMetadata.getJavaType()))) | ||||||||||||||||||
| // The session properties collected here are used for events only. Filter out nulls to avoid problems with downstream consumers | ||||||||||||||||||
|
||||||||||||||||||
| log.debug("File created: query: %s, schema: %s, table: %s, partition: '%s', format: %s, size: %s, path: %s", | |
| writeCompletedEvent.getQueryId(), | |
| writeCompletedEvent.getSchemaName(), | |
| writeCompletedEvent.getTableName(), | |
| writeCompletedEvent.getPartitionName(), | |
| writeCompletedEvent.getStorageFormat(), | |
| writeCompletedEvent.getBytes(), | |
| writeCompletedEvent.getPath()); |
Including null values could be a breaking change to downstream even consumers (e.g. if the [Immutable]Map.copyOf(event.getSessionProperties()). Converting values to Optional would be a breaking change to. In the absence of more information, i deemed that omitting null values is the least breaking of all options.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.tests.product.launcher.env.environment; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import io.trino.tests.product.launcher.docker.DockerFiles; | ||
| import io.trino.tests.product.launcher.docker.DockerFiles.ResourceProvider; | ||
| import io.trino.tests.product.launcher.env.Environment; | ||
| import io.trino.tests.product.launcher.env.EnvironmentProvider; | ||
| import io.trino.tests.product.launcher.env.common.Hadoop; | ||
| import io.trino.tests.product.launcher.env.common.Standard; | ||
| import io.trino.tests.product.launcher.env.common.TestsEnvironment; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| import static io.trino.tests.product.launcher.env.EnvironmentContainers.COORDINATOR; | ||
| import static io.trino.tests.product.launcher.env.common.Hadoop.CONTAINER_PRESTO_HIVE_PROPERTIES; | ||
| import static io.trino.tests.product.launcher.env.common.Hadoop.CONTAINER_PRESTO_ICEBERG_PROPERTIES; | ||
| import static org.testcontainers.utility.MountableFile.forHostPath; | ||
|
|
||
| @TestsEnvironment | ||
| public class EnvSinglenodeHiveIcebergRedirections | ||
| extends EnvironmentProvider | ||
| { | ||
| private final ResourceProvider configDir; | ||
|
|
||
| @Inject | ||
| public EnvSinglenodeHiveIcebergRedirections(DockerFiles dockerFiles, Standard standard, Hadoop hadoop) | ||
| { | ||
| super(ImmutableList.of(standard, hadoop)); | ||
| configDir = dockerFiles.getDockerFilesHostDirectory("conf/environment/singlenode-hive-iceberg-redirections"); | ||
| } | ||
|
|
||
| @Override | ||
| public void extendEnvironment(Environment.Builder builder) | ||
| { | ||
| builder.configureContainer(COORDINATOR, container -> container | ||
| .withCopyFileToContainer(forHostPath(configDir.getPath("hive.properties")), CONTAINER_PRESTO_HIVE_PROPERTIES) | ||
| .withCopyFileToContainer(forHostPath(configDir.getPath("iceberg.properties")), CONTAINER_PRESTO_ICEBERG_PROPERTIES)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| connector.name=hive-hadoop2 | ||
| hive.metastore.uri=thrift://hadoop-master:9083 | ||
| hive.config.resources=/docker/presto-product-tests/conf/presto/etc/hive-default-fs-site.xml | ||
| hive.allow-add-column=true | ||
| hive.allow-drop-column=true | ||
| hive.allow-rename-column=true | ||
| hive.allow-comment-table=true | ||
| hive.allow-drop-table=true | ||
| hive.allow-rename-table=true | ||
| hive.iceberg-catalog-name=iceberg |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| connector.name=iceberg | ||
| hive.metastore.uri=thrift://hadoop-master:9083 | ||
| hive.config.resources=/docker/presto-product-tests/conf/presto/etc/hive-default-fs-site.xml |
Uh oh!
There was an error while loading. Please reload this page.