omarsmak commented on a change in pull request #3326:
URL: https://github.com/apache/iceberg/pull/3326#discussion_r732721065
##########
File path: core/src/main/java/org/apache/iceberg/CatalogUtil.java
##########
@@ -208,23 +201,14 @@ public static Catalog loadCatalog(
*/
public static Catalog buildIcebergCatalog(String name, Map<String, String>
options, Configuration conf) {
String catalogImpl = options.get(CatalogProperties.CATALOG_IMPL);
+ String catalogType = options.get(CatalogProperties.CATALOG_TYPE);
+ Preconditions.checkArgument(catalogImpl == null || catalogType == null,
+ "Cannot create catalog %s, both type and catalog-impl are set:
type=%s, catalog-impl=%s",
Review comment:
nit: indent space here should be `4`.
##########
File path: core/src/main/java/org/apache/iceberg/CatalogUtil.java
##########
@@ -208,23 +201,14 @@ public static Catalog loadCatalog(
*/
public static Catalog buildIcebergCatalog(String name, Map<String, String>
options, Configuration conf) {
String catalogImpl = options.get(CatalogProperties.CATALOG_IMPL);
+ String catalogType = options.get(CatalogProperties.CATALOG_TYPE);
+ Preconditions.checkArgument(catalogImpl == null || catalogType == null,
+ "Cannot create catalog %s, both type and catalog-impl are set:
type=%s, catalog-impl=%s",
+ name, catalogType, catalogImpl);
+
if (catalogImpl == null) {
- String catalogType = PropertyUtil.propertyAsString(options,
ICEBERG_CATALOG_TYPE, ICEBERG_CATALOG_TYPE_HIVE);
- switch (catalogType.toLowerCase(Locale.ENGLISH)) {
- case ICEBERG_CATALOG_TYPE_HIVE:
- catalogImpl = ICEBERG_CATALOG_HIVE;
- break;
- case ICEBERG_CATALOG_TYPE_HADOOP:
- catalogImpl = ICEBERG_CATALOG_HADOOP;
- break;
- default:
- throw new UnsupportedOperationException("Unknown catalog type: " +
catalogType);
- }
- } else {
- String catalogType = options.get(ICEBERG_CATALOG_TYPE);
- Preconditions.checkArgument(catalogType == null,
- "Cannot create catalog %s, both type and catalog-impl are set:
type=%s, catalog-impl=%s",
- name, catalogType, catalogImpl);
+ catalogType = (catalogType == null) ? CatalogType.HIVE.typeName() :
catalogType;
Review comment:
Do we need to check for `catalogType == null` here? There is no way we
will have both `null`s here
##########
File path: nessie/src/test/java/org/apache/iceberg/nessie/TestCatalog.java
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.nessie;
+
+import org.apache.iceberg.CatalogType;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+public class TestCatalog {
Review comment:
Is this test needed? I guess we are doing the same thing in
`TestCatalogType`, isn't?
##########
File path: core/src/main/java/org/apache/iceberg/CatalogType.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import java.util.Locale;
+
+public enum CatalogType {
+ HIVE("org.apache.iceberg.hive.HiveCatalog"),
+ HADOOP("org.apache.iceberg.hadoop.HadoopCatalog"),
+ GLUE("org.apache.iceberg.aws.glue.GlueCatalog"),
+ NESSIE("org.apache.iceberg.nessie.NessieCatalog"),
+ DYNAMODB("org.apache.iceberg.aws.dynamodb.DynamoDbCatalog"),
+ JDBC("org.apache.iceberg.jdbc.JdbcCatalog");
+
+ private final String catalogImpl;
+
+ CatalogType(String catalogImpl) {
+ this.catalogImpl = catalogImpl;
+ }
+
+ public String typeName() {
+ return this.name().toLowerCase(Locale.ENGLISH);
+ }
+
+ public String getCatalogImpl() {
+ return this.catalogImpl;
+ }
+
+ public static String getCatalogImpl(String inputType) {
+ if (inputType == null) {
+ return null;
+ }
+ try {
+ CatalogType type =
CatalogType.valueOf(inputType.toUpperCase(Locale.ENGLISH));
+ return type.getCatalogImpl();
+ } catch (IllegalArgumentException e) {
+ throw new UnsupportedOperationException("Unknown catalog type: " +
inputType);
Review comment:
I guess we can change this message to also include the choices we have
here `Unknown catalog type: %s. (Must be 'hive', 'hadoop', ''glue', 'nessie',
'dynamodb', or 'jdbc')`
##########
File path: core/src/test/java/org/apache/iceberg/TestCatalogType.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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;
+
+import java.util.List;
+import org.apache.iceberg.hadoop.HadoopCatalog;
+import org.apache.iceberg.jdbc.JdbcCatalog;
+import org.assertj.core.api.Assertions;
+import org.assertj.core.util.Lists;
+import org.junit.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class TestCatalogType {
+
+ @ParameterizedTest
+ @MethodSource("mixedCaseCatalogTypeImpls")
+ public void testCaseInsensitivity(Arguments inputCase) {
+ String inputType = (inputCase.get()[0] != null) ? (String)
inputCase.get()[0] : null;
+
Assertions.assertThat(CatalogType.getCatalogImpl(inputType)).isEqualTo(inputCase.get()[1]);
+ }
+
+ private List<Arguments> mixedCaseCatalogTypeImpls() {
Review comment:
I think the method source should be `static`
##########
File path: core/src/test/java/org/apache/iceberg/TestCatalogType.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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;
+
+import java.util.List;
+import org.apache.iceberg.hadoop.HadoopCatalog;
+import org.apache.iceberg.jdbc.JdbcCatalog;
+import org.assertj.core.api.Assertions;
+import org.assertj.core.util.Lists;
+import org.junit.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class TestCatalogType {
+
+ @ParameterizedTest
+ @MethodSource("mixedCaseCatalogTypeImpls")
+ public void testCaseInsensitivity(Arguments inputCase) {
+ String inputType = (inputCase.get()[0] != null) ? (String)
inputCase.get()[0] : null;
+
Assertions.assertThat(CatalogType.getCatalogImpl(inputType)).isEqualTo(inputCase.get()[1]);
+ }
+
+ private List<Arguments> mixedCaseCatalogTypeImpls() {
Review comment:
Shouldn't also return `Stream<Arguments>`?
##########
File path: core/src/main/java/org/apache/iceberg/CatalogType.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import java.util.Locale;
+
+public enum CatalogType {
+ HIVE("org.apache.iceberg.hive.HiveCatalog"),
+ HADOOP("org.apache.iceberg.hadoop.HadoopCatalog"),
+ GLUE("org.apache.iceberg.aws.glue.GlueCatalog"),
+ NESSIE("org.apache.iceberg.nessie.NessieCatalog"),
+ DYNAMODB("org.apache.iceberg.aws.dynamodb.DynamoDbCatalog"),
+ JDBC("org.apache.iceberg.jdbc.JdbcCatalog");
+
+ private final String catalogImpl;
+
+ CatalogType(String catalogImpl) {
+ this.catalogImpl = catalogImpl;
+ }
+
+ public String typeName() {
+ return this.name().toLowerCase(Locale.ENGLISH);
Review comment:
I am wondering if we would name this method to `getTypeName` or
`getName`.
##########
File path: core/src/main/java/org/apache/iceberg/CatalogType.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import java.util.Locale;
+
+public enum CatalogType {
+ HIVE("org.apache.iceberg.hive.HiveCatalog"),
+ HADOOP("org.apache.iceberg.hadoop.HadoopCatalog"),
+ GLUE("org.apache.iceberg.aws.glue.GlueCatalog"),
+ NESSIE("org.apache.iceberg.nessie.NessieCatalog"),
+ DYNAMODB("org.apache.iceberg.aws.dynamodb.DynamoDbCatalog"),
+ JDBC("org.apache.iceberg.jdbc.JdbcCatalog");
+
+ private final String catalogImpl;
+
+ CatalogType(String catalogImpl) {
+ this.catalogImpl = catalogImpl;
+ }
+
+ public String typeName() {
+ return this.name().toLowerCase(Locale.ENGLISH);
+ }
+
+ public String getCatalogImpl() {
+ return this.catalogImpl;
Review comment:
here as well
##########
File path: mr/src/test/java/org/apache/iceberg/mr/hive/TestTables.java
##########
@@ -414,14 +415,14 @@ public Table loadTable(TableIdentifier identifier) {
static class HiveTestTables extends TestTables {
HiveTestTables(Configuration conf, TemporaryFolder temp, String
catalogName) {
- super(CatalogUtil.loadCatalog(HiveCatalog.class.getName(),
CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE,
+ super(CatalogUtil.loadCatalog(HiveCatalog.class.getName(),
CatalogType.HIVE.typeName(),
ImmutableMap.of(), conf), temp, catalogName);
}
@Override
public Map<String, String> properties() {
- return
ImmutableMap.of(InputFormatConfig.catalogPropertyConfigKey(catalog,
CatalogUtil.ICEBERG_CATALOG_TYPE),
- CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE);
+ return
ImmutableMap.of(InputFormatConfig.catalogPropertyConfigKey(catalog,
CatalogProperties.CATALOG_TYPE),
+ CatalogType.HIVE.typeName());
Review comment:
indent space 4 here as well
##########
File path: core/src/main/java/org/apache/iceberg/CatalogType.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import java.util.Locale;
+
+public enum CatalogType {
+ HIVE("org.apache.iceberg.hive.HiveCatalog"),
+ HADOOP("org.apache.iceberg.hadoop.HadoopCatalog"),
+ GLUE("org.apache.iceberg.aws.glue.GlueCatalog"),
+ NESSIE("org.apache.iceberg.nessie.NessieCatalog"),
+ DYNAMODB("org.apache.iceberg.aws.dynamodb.DynamoDbCatalog"),
+ JDBC("org.apache.iceberg.jdbc.JdbcCatalog");
+
+ private final String catalogImpl;
+
+ CatalogType(String catalogImpl) {
+ this.catalogImpl = catalogImpl;
+ }
+
+ public String typeName() {
+ return this.name().toLowerCase(Locale.ENGLISH);
Review comment:
`this` is not needed 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]