You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "nk1506 (via GitHub)" <gi...@apache.org> on 2023/11/09 05:14:22 UTC
[PR] Refactor HiveTableOperations with common code for View. [iceberg]
nk1506 opened a new pull request, #9011:
URL: https://github.com/apache/iceberg/pull/9011
As part of issues #8698 , All the common piece between table and view has been moved from `HiveTableOperations` to a new helper class.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1389341091
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetastoreConnector.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveMetastoreConnector {
+
+ Logger LOG = LoggerFactory.getLogger(HiveMetastoreConnector.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ boolean exposeInHmsProperties();
+
+ ClientPool<IMetaStoreClient, TException> getMetaClients();
+
+ long getMaxHiveTablePropertySize();
+
+ String database();
+
+ String table();
+
+ Map<String, String> hmsEnvContext(String metadataLocation);
+
+ default void setSchema(TableMetadata metadata, Map<String, String> parameters) {
+ parameters.remove(TableProperties.CURRENT_SCHEMA);
+ if (exposeInHmsProperties() && metadata.schema() != null) {
+ String schema = SchemaParser.toJson(metadata.schema());
+ setField(parameters, TableProperties.CURRENT_SCHEMA, schema);
+ }
+ }
+
+ default void setField(Map<String, String> parameters, String key, String value) {
+ if (value.length() <= getMaxHiveTablePropertySize()) {
+ parameters.put(key, value);
+ } else {
+ LOG.warn(
+ "Not exposing {} in HMS since it exceeds {} characters",
+ key,
+ getMaxHiveTablePropertySize());
+ }
+ }
+
+ static void validateTableIsIceberg(Table table, String fullName) {
+ String tableType = table.getParameters().get(BaseMetastoreTableOperations.TABLE_TYPE_PROP);
+ NoSuchIcebergTableException.check(
+ tableType != null
+ && tableType.equalsIgnoreCase(BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE),
+ "Not an iceberg table: %s (type=%s)",
+ fullName,
+ tableType);
+ }
+
+ default void persistTable(Table hmsTable, boolean updateHiveTable, String metadataLocation)
+ throws TException, InterruptedException {
+ if (updateHiveTable) {
+ getMetaClients()
+ .run(
+ client -> {
+ MetastoreUtil.alterTable(
+ client, database(), table(), hmsTable, hmsEnvContext(metadataLocation));
+ return null;
+ });
+ } else {
+ getMetaClients()
+ .run(
+ client -> {
+ client.createTable(hmsTable);
+ return null;
+ });
+ }
+ }
+
+ default StorageDescriptor storageDescriptor(TableMetadata metadata, boolean hiveEngineEnabled) {
+
+ final StorageDescriptor storageDescriptor = new StorageDescriptor();
+ storageDescriptor.setCols(HiveSchemaUtil.convert(metadata.schema()));
+ storageDescriptor.setLocation(metadata.location());
+ SerDeInfo serDeInfo = new SerDeInfo();
+ serDeInfo.setParameters(Maps.newHashMap());
+ if (hiveEngineEnabled) {
+ storageDescriptor.setInputFormat("org.apache.iceberg.mr.hive.HiveIcebergInputFormat");
+ storageDescriptor.setOutputFormat("org.apache.iceberg.mr.hive.HiveIcebergOutputFormat");
+ serDeInfo.setSerializationLib("org.apache.iceberg.mr.hive.HiveIcebergSerDe");
+ } else {
+ storageDescriptor.setOutputFormat("org.apache.hadoop.mapred.FileOutputFormat");
+ storageDescriptor.setInputFormat("org.apache.hadoop.mapred.FileInputFormat");
+ serDeInfo.setSerializationLib("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe");
+ }
+ storageDescriptor.setSerdeInfo(serDeInfo);
+ return storageDescriptor;
+ }
+
+ default void cleanupMetadata(FileIO fileIO, String commitStatus, String metadataLocation) {
Review Comment:
Could this be static?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1400329609
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -207,11 +195,15 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
updateHiveTable = true;
LOG.debug("Committing existing table: {}", fullName);
} else {
- tbl = newHmsTable(metadata);
+ tbl =
+ newHmsTable(
+ metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));
Review Comment:
I am really sorry for missing this before.
Why do we set this generally in the `newHmsTable`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1389355915
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -156,7 +147,7 @@ protected void doRefresh() {
String metadataLocation = null;
try {
Table table = metaClients.run(client -> client.getTable(database, tableName));
- validateTableIsIceberg(table, fullName);
+ HiveMetastoreConnector.validateTableIsIceberg(table, fullName);
Review Comment:
`HiveMetastoreConnector` is not need here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "nk1506 (via GitHub)" <gi...@apache.org>.
nk1506 commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1391553311
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetastoreConnector.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveMetastoreConnector {
+
+ Logger LOG = LoggerFactory.getLogger(HiveMetastoreConnector.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ boolean exposeInHmsProperties();
+
+ ClientPool<IMetaStoreClient, TException> getMetaClients();
+
+ long getMaxHiveTablePropertySize();
Review Comment:
Yes, i should have avoided `get `.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1403960661
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -207,11 +195,15 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
updateHiveTable = true;
LOG.debug("Committing existing table: {}", fullName);
} else {
- tbl = newHmsTable(metadata);
+ tbl =
+ newHmsTable(
+ metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));
Review Comment:
Probably it would be the best to have a common interface for the 2, but we should not hold back this part for it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1389343659
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetastoreConnector.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveMetastoreConnector {
+
+ Logger LOG = LoggerFactory.getLogger(HiveMetastoreConnector.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ boolean exposeInHmsProperties();
+
+ ClientPool<IMetaStoreClient, TException> getMetaClients();
+
+ long getMaxHiveTablePropertySize();
+
+ String database();
+
+ String table();
+
+ Map<String, String> hmsEnvContext(String metadataLocation);
+
+ default void setSchema(TableMetadata metadata, Map<String, String> parameters) {
+ parameters.remove(TableProperties.CURRENT_SCHEMA);
+ if (exposeInHmsProperties() && metadata.schema() != null) {
+ String schema = SchemaParser.toJson(metadata.schema());
+ setField(parameters, TableProperties.CURRENT_SCHEMA, schema);
+ }
+ }
+
+ default void setField(Map<String, String> parameters, String key, String value) {
+ if (value.length() <= getMaxHiveTablePropertySize()) {
+ parameters.put(key, value);
+ } else {
+ LOG.warn(
+ "Not exposing {} in HMS since it exceeds {} characters",
+ key,
+ getMaxHiveTablePropertySize());
+ }
+ }
+
+ static void validateTableIsIceberg(Table table, String fullName) {
+ String tableType = table.getParameters().get(BaseMetastoreTableOperations.TABLE_TYPE_PROP);
+ NoSuchIcebergTableException.check(
+ tableType != null
+ && tableType.equalsIgnoreCase(BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE),
+ "Not an iceberg table: %s (type=%s)",
+ fullName,
+ tableType);
+ }
+
+ default void persistTable(Table hmsTable, boolean updateHiveTable, String metadataLocation)
+ throws TException, InterruptedException {
+ if (updateHiveTable) {
+ getMetaClients()
+ .run(
+ client -> {
+ MetastoreUtil.alterTable(
+ client, database(), table(), hmsTable, hmsEnvContext(metadataLocation));
+ return null;
+ });
+ } else {
+ getMetaClients()
+ .run(
+ client -> {
+ client.createTable(hmsTable);
+ return null;
+ });
+ }
+ }
+
+ default StorageDescriptor storageDescriptor(TableMetadata metadata, boolean hiveEngineEnabled) {
+
+ final StorageDescriptor storageDescriptor = new StorageDescriptor();
+ storageDescriptor.setCols(HiveSchemaUtil.convert(metadata.schema()));
+ storageDescriptor.setLocation(metadata.location());
+ SerDeInfo serDeInfo = new SerDeInfo();
+ serDeInfo.setParameters(Maps.newHashMap());
+ if (hiveEngineEnabled) {
+ storageDescriptor.setInputFormat("org.apache.iceberg.mr.hive.HiveIcebergInputFormat");
+ storageDescriptor.setOutputFormat("org.apache.iceberg.mr.hive.HiveIcebergOutputFormat");
+ serDeInfo.setSerializationLib("org.apache.iceberg.mr.hive.HiveIcebergSerDe");
+ } else {
+ storageDescriptor.setOutputFormat("org.apache.hadoop.mapred.FileOutputFormat");
+ storageDescriptor.setInputFormat("org.apache.hadoop.mapred.FileInputFormat");
+ serDeInfo.setSerializationLib("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe");
+ }
+ storageDescriptor.setSerdeInfo(serDeInfo);
+ return storageDescriptor;
+ }
+
+ default void cleanupMetadata(FileIO fileIO, String commitStatus, String metadataLocation) {
+ try {
+ if (commitStatus.equalsIgnoreCase("FAILURE")) {
+ // If we are sure the commit failed, clean up the uncommitted metadata file
+ fileIO.deleteFile(metadataLocation);
+ }
+ } catch (RuntimeException e) {
+ LOG.error("Failed to cleanup metadata file at {}", metadataLocation, e);
+ }
+ }
+
+ default Table newHmsTable(String hmsTableOwner) {
Review Comment:
Could this be `static`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary merged PR #9011:
URL: https://github.com/apache/iceberg/pull/9011
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1396283697
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveOperationsBase.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveOperationsBase {
+
+ Logger LOG = LoggerFactory.getLogger(HiveOperationsBase.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ ClientPool<IMetaStoreClient, TException> metaClients();
+
+ long maxHiveTablePropertySize();
+
+ String database();
+
+ String table();
+
+ Map<String, String> hmsEnvContext(String metadataLocation);
Review Comment:
The goal of this setting is to send a map to Hive, that only execute the update, if the `METADATA_LOCATION_PROP` is still `expectedMetadataLocation`.
If for the views we still use the metadata location, then we probably want to use the same config here as for the tables.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1395930004
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveOperationsBase.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveOperationsBase {
+
+ Logger LOG = LoggerFactory.getLogger(HiveOperationsBase.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ ClientPool<IMetaStoreClient, TException> metaClients();
+
+ long maxHiveTablePropertySize();
+
+ String database();
+
+ String table();
+
+ Map<String, String> hmsEnvContext(String metadataLocation);
Review Comment:
How will this work for View-s?
Any thoughts here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#issuecomment-1814715417
I have one question left, which is somewhat related to the new usage of the `HiveOperationsBase`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#issuecomment-1825177267
Thanks for all the work and patience @nk1506 !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1389352401
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetastoreConnector.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveMetastoreConnector {
Review Comment:
Maybe HiveOperationsBase? Or something similar?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1389339429
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetastoreConnector.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveMetastoreConnector {
+
+ Logger LOG = LoggerFactory.getLogger(HiveMetastoreConnector.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ boolean exposeInHmsProperties();
Review Comment:
We can have a default implementation of this based on `getMaxHiveTablePropertySize`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "nk1506 (via GitHub)" <gi...@apache.org>.
nk1506 commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1391550697
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -156,7 +147,7 @@ protected void doRefresh() {
String metadataLocation = null;
try {
Table table = metaClients.run(client -> client.getTable(database, tableName));
- validateTableIsIceberg(table, fullName);
+ HiveMetastoreConnector.validateTableIsIceberg(table, fullName);
Review Comment:
`validateTableIsIceberg` is a static method and being referred from non-static method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1389343659
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetastoreConnector.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveMetastoreConnector {
+
+ Logger LOG = LoggerFactory.getLogger(HiveMetastoreConnector.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ boolean exposeInHmsProperties();
+
+ ClientPool<IMetaStoreClient, TException> getMetaClients();
+
+ long getMaxHiveTablePropertySize();
+
+ String database();
+
+ String table();
+
+ Map<String, String> hmsEnvContext(String metadataLocation);
+
+ default void setSchema(TableMetadata metadata, Map<String, String> parameters) {
+ parameters.remove(TableProperties.CURRENT_SCHEMA);
+ if (exposeInHmsProperties() && metadata.schema() != null) {
+ String schema = SchemaParser.toJson(metadata.schema());
+ setField(parameters, TableProperties.CURRENT_SCHEMA, schema);
+ }
+ }
+
+ default void setField(Map<String, String> parameters, String key, String value) {
+ if (value.length() <= getMaxHiveTablePropertySize()) {
+ parameters.put(key, value);
+ } else {
+ LOG.warn(
+ "Not exposing {} in HMS since it exceeds {} characters",
+ key,
+ getMaxHiveTablePropertySize());
+ }
+ }
+
+ static void validateTableIsIceberg(Table table, String fullName) {
+ String tableType = table.getParameters().get(BaseMetastoreTableOperations.TABLE_TYPE_PROP);
+ NoSuchIcebergTableException.check(
+ tableType != null
+ && tableType.equalsIgnoreCase(BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE),
+ "Not an iceberg table: %s (type=%s)",
+ fullName,
+ tableType);
+ }
+
+ default void persistTable(Table hmsTable, boolean updateHiveTable, String metadataLocation)
+ throws TException, InterruptedException {
+ if (updateHiveTable) {
+ getMetaClients()
+ .run(
+ client -> {
+ MetastoreUtil.alterTable(
+ client, database(), table(), hmsTable, hmsEnvContext(metadataLocation));
+ return null;
+ });
+ } else {
+ getMetaClients()
+ .run(
+ client -> {
+ client.createTable(hmsTable);
+ return null;
+ });
+ }
+ }
+
+ default StorageDescriptor storageDescriptor(TableMetadata metadata, boolean hiveEngineEnabled) {
+
+ final StorageDescriptor storageDescriptor = new StorageDescriptor();
+ storageDescriptor.setCols(HiveSchemaUtil.convert(metadata.schema()));
+ storageDescriptor.setLocation(metadata.location());
+ SerDeInfo serDeInfo = new SerDeInfo();
+ serDeInfo.setParameters(Maps.newHashMap());
+ if (hiveEngineEnabled) {
+ storageDescriptor.setInputFormat("org.apache.iceberg.mr.hive.HiveIcebergInputFormat");
+ storageDescriptor.setOutputFormat("org.apache.iceberg.mr.hive.HiveIcebergOutputFormat");
+ serDeInfo.setSerializationLib("org.apache.iceberg.mr.hive.HiveIcebergSerDe");
+ } else {
+ storageDescriptor.setOutputFormat("org.apache.hadoop.mapred.FileOutputFormat");
+ storageDescriptor.setInputFormat("org.apache.hadoop.mapred.FileInputFormat");
+ serDeInfo.setSerializationLib("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe");
+ }
+ storageDescriptor.setSerdeInfo(serDeInfo);
+ return storageDescriptor;
+ }
+
+ default void cleanupMetadata(FileIO fileIO, String commitStatus, String metadataLocation) {
+ try {
+ if (commitStatus.equalsIgnoreCase("FAILURE")) {
+ // If we are sure the commit failed, clean up the uncommitted metadata file
+ fileIO.deleteFile(metadataLocation);
+ }
+ } catch (RuntimeException e) {
+ LOG.error("Failed to cleanup metadata file at {}", metadataLocation, e);
+ }
+ }
+
+ default Table newHmsTable(String hmsTableOwner) {
Review Comment:
Could this be `static`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "nk1506 (via GitHub)" <gi...@apache.org>.
nk1506 commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1403606978
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -207,11 +195,15 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
updateHiveTable = true;
LOG.debug("Committing existing table: {}", fullName);
} else {
- tbl = newHmsTable(metadata);
+ tbl =
+ newHmsTable(
+ metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));
Review Comment:
[TableMetadata](https://github.com/apache/iceberg/blob/c1190990760509e40dd8e10092196a569d684f1b/core/src/main/java/org/apache/iceberg/TableMetadata.java) and [ViewMetadata](https://github.com/apache/iceberg/blob/c1190990760509e40dd8e10092196a569d684f1b/core/src/main/java/org/apache/iceberg/view/ViewMetadata.java) both are unrelated. I am not able to find a better approach with `newHmsTable(TableMetadata metadata) `.
Please suggest.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "nk1506 (via GitHub)" <gi...@apache.org>.
nk1506 commented on PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#issuecomment-1825492456
Thanks @pvary for suggesting and reviewing this. I will start rebasing View [PR](https://github.com/apache/iceberg/pull/8907).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1403245669
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -207,11 +195,15 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
updateHiveTable = true;
LOG.debug("Committing existing table: {}", fullName);
} else {
- tbl = newHmsTable(metadata);
+ tbl =
+ newHmsTable(
+ metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));
Review Comment:
You might be better positioned to suggest things from the `View` point of view 😄, but if it were only me, then I would have created the following method in `HiveOperationsBase`:
```
default Table newHmsTable(TableMetadata metadata) {
[..]
}
```
and kept the implementation the same (using the same metadata key to get the owner), like before:
```
Preconditions.checkNotNull(metadata, "'metadata' parameter can't be null");
final long currentTimeMillis = System.currentTimeMillis();
Table newTable =
new Table(
tableName,
database,
metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()),
(int) currentTimeMillis / 1000,
(int) currentTimeMillis / 1000,
Integer.MAX_VALUE,
null,
Collections.emptyList(),
Maps.newHashMap(),
null,
null,
TableType.EXTERNAL_TABLE.toString());
newTable
.getParameters()
.put("EXTERNAL", "TRUE"); // using the external table type also requires this
return newTable;
```
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -207,11 +195,15 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
updateHiveTable = true;
LOG.debug("Committing existing table: {}", fullName);
} else {
- tbl = newHmsTable(metadata);
+ tbl =
+ newHmsTable(
+ metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));
Review Comment:
You might be better positioned to suggest things from the `View` point of view 😄, but if it were only me, then I would have created the following method in `HiveOperationsBase`:
```
default Table newHmsTable(TableMetadata metadata) {
[..]
}
```
and kept the implementation the same (using the same metadata key to get the owner), like before:
```
Preconditions.checkNotNull(metadata, "'metadata' parameter can't be null");
final long currentTimeMillis = System.currentTimeMillis();
Table newTable =
new Table(
tableName,
database,
metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()),
(int) currentTimeMillis / 1000,
(int) currentTimeMillis / 1000,
Integer.MAX_VALUE,
null,
Collections.emptyList(),
Maps.newHashMap(),
null,
null,
TableType.EXTERNAL_TABLE.toString());
newTable
.getParameters()
.put("EXTERNAL", "TRUE"); // using the external table type also requires this
return newTable;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1400329609
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -207,11 +195,15 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
updateHiveTable = true;
LOG.debug("Committing existing table: {}", fullName);
} else {
- tbl = newHmsTable(metadata);
+ tbl =
+ newHmsTable(
+ metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));
Review Comment:
I am really sorry for missing this before.
Should we set this generally in the `newHmsTable`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "nk1506 (via GitHub)" <gi...@apache.org>.
nk1506 commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1401665955
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -207,11 +195,15 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
updateHiveTable = true;
LOG.debug("Committing existing table: {}", fullName);
} else {
- tbl = newHmsTable(metadata);
+ tbl =
+ newHmsTable(
+ metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));
Review Comment:
Yes, it was fetching [tableOwner](https://github.com/apache/iceberg/blob/229a243ddad20a725d9f7e4446ce8bb3fc2c9a53/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java#L369) from TableMetadata.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1389307575
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetastoreConnector.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveMetastoreConnector {
+
+ Logger LOG = LoggerFactory.getLogger(HiveMetastoreConnector.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ boolean exposeInHmsProperties();
+
+ ClientPool<IMetaStoreClient, TException> getMetaClients();
Review Comment:
Why did you decided to use `get` in the method name?
In Iceberg we usually avoid `get`
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetastoreConnector.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveMetastoreConnector {
+
+ Logger LOG = LoggerFactory.getLogger(HiveMetastoreConnector.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ boolean exposeInHmsProperties();
+
+ ClientPool<IMetaStoreClient, TException> getMetaClients();
+
+ long getMaxHiveTablePropertySize();
Review Comment:
Why did you decided to use `get` in the method name?
In Iceberg we usually avoid `get`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1389340756
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetastoreConnector.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveMetastoreConnector {
+
+ Logger LOG = LoggerFactory.getLogger(HiveMetastoreConnector.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ boolean exposeInHmsProperties();
+
+ ClientPool<IMetaStoreClient, TException> getMetaClients();
+
+ long getMaxHiveTablePropertySize();
+
+ String database();
+
+ String table();
+
+ Map<String, String> hmsEnvContext(String metadataLocation);
+
+ default void setSchema(TableMetadata metadata, Map<String, String> parameters) {
+ parameters.remove(TableProperties.CURRENT_SCHEMA);
+ if (exposeInHmsProperties() && metadata.schema() != null) {
+ String schema = SchemaParser.toJson(metadata.schema());
+ setField(parameters, TableProperties.CURRENT_SCHEMA, schema);
+ }
+ }
+
+ default void setField(Map<String, String> parameters, String key, String value) {
+ if (value.length() <= getMaxHiveTablePropertySize()) {
+ parameters.put(key, value);
+ } else {
+ LOG.warn(
+ "Not exposing {} in HMS since it exceeds {} characters",
+ key,
+ getMaxHiveTablePropertySize());
+ }
+ }
+
+ static void validateTableIsIceberg(Table table, String fullName) {
+ String tableType = table.getParameters().get(BaseMetastoreTableOperations.TABLE_TYPE_PROP);
+ NoSuchIcebergTableException.check(
+ tableType != null
+ && tableType.equalsIgnoreCase(BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE),
+ "Not an iceberg table: %s (type=%s)",
+ fullName,
+ tableType);
+ }
+
+ default void persistTable(Table hmsTable, boolean updateHiveTable, String metadataLocation)
+ throws TException, InterruptedException {
+ if (updateHiveTable) {
+ getMetaClients()
+ .run(
+ client -> {
+ MetastoreUtil.alterTable(
+ client, database(), table(), hmsTable, hmsEnvContext(metadataLocation));
+ return null;
+ });
+ } else {
+ getMetaClients()
+ .run(
+ client -> {
+ client.createTable(hmsTable);
+ return null;
+ });
+ }
+ }
+
+ default StorageDescriptor storageDescriptor(TableMetadata metadata, boolean hiveEngineEnabled) {
Review Comment:
Could this be `static`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1401876287
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -207,11 +195,15 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
updateHiveTable = true;
LOG.debug("Committing existing table: {}", fullName);
} else {
- tbl = newHmsTable(metadata);
+ tbl =
+ newHmsTable(
+ metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));
Review Comment:
Don't we have the same `tableOwner` for views as well?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "nk1506 (via GitHub)" <gi...@apache.org>.
nk1506 commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1402866684
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -207,11 +195,15 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
updateHiveTable = true;
LOG.debug("Committing existing table: {}", fullName);
} else {
- tbl = newHmsTable(metadata);
+ tbl =
+ newHmsTable(
+ metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));
Review Comment:
For views, I thought it's always going to be [CurrentUser](https://github.com/apache/iceberg/pull/8907/files#diff-db46657b84d66e084e15f31b8dab21577efb2ae7102863f94c6c9477782de676R320). But I think it makes sense to get the tableOwner from ViewMetadata as well if Present.
Still we will have to expect user information from Caller of `newHmsTable` , right?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "nk1506 (via GitHub)" <gi...@apache.org>.
nk1506 commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1402866684
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -207,11 +195,15 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
updateHiveTable = true;
LOG.debug("Committing existing table: {}", fullName);
} else {
- tbl = newHmsTable(metadata);
+ tbl =
+ newHmsTable(
+ metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));
Review Comment:
For views, I thought it's always going to be [CurrentUser](https://github.com/apache/iceberg/pull/8907/files#diff-db46657b84d66e084e15f31b8dab21577efb2ae7102863f94c6c9477782de676R320). But I think it makes sense to get the tableOwner from ViewMetadata as well if Present.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1389343294
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetastoreConnector.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveMetastoreConnector {
+
+ Logger LOG = LoggerFactory.getLogger(HiveMetastoreConnector.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ boolean exposeInHmsProperties();
+
+ ClientPool<IMetaStoreClient, TException> getMetaClients();
+
+ long getMaxHiveTablePropertySize();
+
+ String database();
+
+ String table();
+
+ Map<String, String> hmsEnvContext(String metadataLocation);
+
+ default void setSchema(TableMetadata metadata, Map<String, String> parameters) {
+ parameters.remove(TableProperties.CURRENT_SCHEMA);
+ if (exposeInHmsProperties() && metadata.schema() != null) {
+ String schema = SchemaParser.toJson(metadata.schema());
+ setField(parameters, TableProperties.CURRENT_SCHEMA, schema);
+ }
+ }
+
+ default void setField(Map<String, String> parameters, String key, String value) {
+ if (value.length() <= getMaxHiveTablePropertySize()) {
+ parameters.put(key, value);
+ } else {
+ LOG.warn(
+ "Not exposing {} in HMS since it exceeds {} characters",
+ key,
+ getMaxHiveTablePropertySize());
+ }
+ }
+
+ static void validateTableIsIceberg(Table table, String fullName) {
+ String tableType = table.getParameters().get(BaseMetastoreTableOperations.TABLE_TYPE_PROP);
+ NoSuchIcebergTableException.check(
+ tableType != null
+ && tableType.equalsIgnoreCase(BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE),
+ "Not an iceberg table: %s (type=%s)",
+ fullName,
+ tableType);
+ }
+
+ default void persistTable(Table hmsTable, boolean updateHiveTable, String metadataLocation)
+ throws TException, InterruptedException {
+ if (updateHiveTable) {
+ getMetaClients()
+ .run(
+ client -> {
+ MetastoreUtil.alterTable(
+ client, database(), table(), hmsTable, hmsEnvContext(metadataLocation));
+ return null;
+ });
+ } else {
+ getMetaClients()
+ .run(
+ client -> {
+ client.createTable(hmsTable);
+ return null;
+ });
+ }
+ }
+
+ default StorageDescriptor storageDescriptor(TableMetadata metadata, boolean hiveEngineEnabled) {
+
+ final StorageDescriptor storageDescriptor = new StorageDescriptor();
+ storageDescriptor.setCols(HiveSchemaUtil.convert(metadata.schema()));
+ storageDescriptor.setLocation(metadata.location());
+ SerDeInfo serDeInfo = new SerDeInfo();
+ serDeInfo.setParameters(Maps.newHashMap());
+ if (hiveEngineEnabled) {
+ storageDescriptor.setInputFormat("org.apache.iceberg.mr.hive.HiveIcebergInputFormat");
+ storageDescriptor.setOutputFormat("org.apache.iceberg.mr.hive.HiveIcebergOutputFormat");
+ serDeInfo.setSerializationLib("org.apache.iceberg.mr.hive.HiveIcebergSerDe");
+ } else {
+ storageDescriptor.setOutputFormat("org.apache.hadoop.mapred.FileOutputFormat");
+ storageDescriptor.setInputFormat("org.apache.hadoop.mapred.FileInputFormat");
+ serDeInfo.setSerializationLib("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe");
+ }
+ storageDescriptor.setSerdeInfo(serDeInfo);
+ return storageDescriptor;
+ }
+
+ default void cleanupMetadata(FileIO fileIO, String commitStatus, String metadataLocation) {
Review Comment:
nit: maybe `io` instead of `fileIO`? - not important, just seems strange to me... 😄
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetastoreConnector.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveMetastoreConnector {
+
+ Logger LOG = LoggerFactory.getLogger(HiveMetastoreConnector.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ boolean exposeInHmsProperties();
+
+ ClientPool<IMetaStoreClient, TException> getMetaClients();
+
+ long getMaxHiveTablePropertySize();
+
+ String database();
+
+ String table();
+
+ Map<String, String> hmsEnvContext(String metadataLocation);
+
+ default void setSchema(TableMetadata metadata, Map<String, String> parameters) {
+ parameters.remove(TableProperties.CURRENT_SCHEMA);
+ if (exposeInHmsProperties() && metadata.schema() != null) {
+ String schema = SchemaParser.toJson(metadata.schema());
+ setField(parameters, TableProperties.CURRENT_SCHEMA, schema);
+ }
+ }
+
+ default void setField(Map<String, String> parameters, String key, String value) {
+ if (value.length() <= getMaxHiveTablePropertySize()) {
+ parameters.put(key, value);
+ } else {
+ LOG.warn(
+ "Not exposing {} in HMS since it exceeds {} characters",
+ key,
+ getMaxHiveTablePropertySize());
+ }
+ }
+
+ static void validateTableIsIceberg(Table table, String fullName) {
+ String tableType = table.getParameters().get(BaseMetastoreTableOperations.TABLE_TYPE_PROP);
+ NoSuchIcebergTableException.check(
+ tableType != null
+ && tableType.equalsIgnoreCase(BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE),
+ "Not an iceberg table: %s (type=%s)",
+ fullName,
+ tableType);
+ }
+
+ default void persistTable(Table hmsTable, boolean updateHiveTable, String metadataLocation)
+ throws TException, InterruptedException {
+ if (updateHiveTable) {
+ getMetaClients()
+ .run(
+ client -> {
+ MetastoreUtil.alterTable(
+ client, database(), table(), hmsTable, hmsEnvContext(metadataLocation));
+ return null;
+ });
+ } else {
+ getMetaClients()
+ .run(
+ client -> {
+ client.createTable(hmsTable);
+ return null;
+ });
+ }
+ }
+
+ default StorageDescriptor storageDescriptor(TableMetadata metadata, boolean hiveEngineEnabled) {
+
+ final StorageDescriptor storageDescriptor = new StorageDescriptor();
+ storageDescriptor.setCols(HiveSchemaUtil.convert(metadata.schema()));
+ storageDescriptor.setLocation(metadata.location());
+ SerDeInfo serDeInfo = new SerDeInfo();
+ serDeInfo.setParameters(Maps.newHashMap());
+ if (hiveEngineEnabled) {
+ storageDescriptor.setInputFormat("org.apache.iceberg.mr.hive.HiveIcebergInputFormat");
+ storageDescriptor.setOutputFormat("org.apache.iceberg.mr.hive.HiveIcebergOutputFormat");
+ serDeInfo.setSerializationLib("org.apache.iceberg.mr.hive.HiveIcebergSerDe");
+ } else {
+ storageDescriptor.setOutputFormat("org.apache.hadoop.mapred.FileOutputFormat");
+ storageDescriptor.setInputFormat("org.apache.hadoop.mapred.FileInputFormat");
+ serDeInfo.setSerializationLib("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe");
+ }
+ storageDescriptor.setSerdeInfo(serDeInfo);
+ return storageDescriptor;
+ }
+
+ default void cleanupMetadata(FileIO fileIO, String commitStatus, String metadataLocation) {
Review Comment:
nit: maybe `io` instead of `fileIO`? - not important, just seems strange to me... 😄
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Refactor HiveTableOperations with common code for View. [iceberg]
Posted by "nk1506 (via GitHub)" <gi...@apache.org>.
nk1506 commented on code in PR #9011:
URL: https://github.com/apache/iceberg/pull/9011#discussion_r1396122380
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveOperationsBase.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.iceberg.hive;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.ClientPool;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** All the HMS operations like table,view,materialized_view should implement this. */
+interface HiveOperationsBase {
+
+ Logger LOG = LoggerFactory.getLogger(HiveOperationsBase.class);
+ // The max size is based on HMS backend database. For Hive versions below 2.3, the max table
+ // parameter size is 4000
+ // characters, see https://issues.apache.org/jira/browse/HIVE-12274
+ // set to 0 to not expose Iceberg metadata in HMS Table properties.
+ String HIVE_TABLE_PROPERTY_MAX_SIZE = "iceberg.hive.table-property-max-size";
+ long HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT = 32672;
+
+ TableType tableType();
+
+ ClientPool<IMetaStoreClient, TException> metaClients();
+
+ long maxHiveTablePropertySize();
+
+ String database();
+
+ String table();
+
+ Map<String, String> hmsEnvContext(String metadataLocation);
Review Comment:
In case of `Table` envContext is looking like [here](https://github.com/apache/iceberg/blob/2e2ac8dfd2ab2c214444cccb0e6024e1f80b0502/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java#L333) .
`expectedMetadataLocation != null
? ImmutableMap.of(
NO_LOCK_EXPECTED_KEY,
METADATA_LOCATION_PROP,
NO_LOCK_EXPECTED_VALUE,
expectedMetadataLocation)
: ImmutableMap.of()`
In case of `View` it will look [like](https://github.com/apache/iceberg/pull/8907/files#diff-db46657b84d66e084e15f31b8dab21577efb2ae7102863f94c6c9477782de676R283)
`expectedMetadataLocation != null
? ImmutableMap.of(
BaseMetastoreTableOperations.METADATA_LOCATION_PROP,
expectedMetadataLocation)
: ImmutableMap.of()`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org