Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.iceberg.view.ViewProperties;
import org.apache.iceberg.view.ViewUtil;
import org.apache.iceberg.view.ViewVersion;
import org.apache.spark.SparkException;
import org.apache.spark.sql.AnalysisException;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
Expand Down Expand Up @@ -1354,12 +1355,9 @@ public void createViewWithSubqueryExpressionUsingTempFunction() {
}

@TestTemplate
@SuppressWarnings("checkstyle:AssertThatThrownByWithMessageCheck")
public void createViewWithSubqueryExpressionInFilterThatIsRewritten()
throws NoSuchTableException {
assumeThat(catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE))
.as(
"Executing subquery expression with Hive fails due to an exception when instantiating the FileInputFormat")
.isNotEqualTo("hive");
insertRows(5);
String viewName = viewName("viewWithSubqueryExpression");
String sql =
Expand All @@ -1370,12 +1368,21 @@ public void createViewWithSubqueryExpressionInFilterThatIsRewritten()

assertThat(sql("SELECT * FROM %s", viewName)).hasSize(1).containsExactly(row(5));

String catalogType = catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE);
if (!catalogName.equals(SPARK_CATALOG)) {
sql("USE spark_catalog");

assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
if ("hive".equals(catalogType)) {
// The Hive view catalog shares its metastore with the default spark_catalog, so the
// Iceberg table IS resolvable there (unlike the in-memory/REST view catalogs) and does
// not raise AnalysisException. It cannot be read natively as a Hive table, so executing
// the raw SQL fails at execution time instead.
assertThatThrownBy(() -> sql(sql)).isInstanceOf(SparkException.class);
} else {
assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
}
}

// the underlying SQL in the View should be rewritten to have catalog & namespace
Expand All @@ -1385,11 +1392,8 @@ public void createViewWithSubqueryExpressionInFilterThatIsRewritten()
}

@TestTemplate
@SuppressWarnings("checkstyle:AssertThatThrownByWithMessageCheck")
public void createViewWithSubqueryExpressionInQueryThatIsRewritten() throws NoSuchTableException {
assumeThat(catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE))
.as(
"Executing subquery expression with Hive fails due to an exception when instantiating the FileInputFormat")
.isNotEqualTo("hive");
insertRows(3);
String viewName = viewName("viewWithSubqueryExpression");
String sql =
Expand All @@ -1401,12 +1405,21 @@ public void createViewWithSubqueryExpressionInQueryThatIsRewritten() throws NoSu
.hasSize(3)
.containsExactly(row(3), row(3), row(3));

String catalogType = catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE);
if (!catalogName.equals(SPARK_CATALOG)) {
sql("USE spark_catalog");

assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
if ("hive".equals(catalogType)) {
// The Hive view catalog shares its metastore with the default spark_catalog, so the
// Iceberg table IS resolvable there (unlike the in-memory/REST view catalogs) and does
// not raise AnalysisException. It cannot be read natively as a Hive table, so executing
// the raw SQL fails at execution time instead.
assertThatThrownBy(() -> sql(sql)).isInstanceOf(SparkException.class);
} else {
assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
}
}

// the underlying SQL in the View should be rewritten to have catalog & namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.iceberg.view.ViewProperties;
import org.apache.iceberg.view.ViewUtil;
import org.apache.iceberg.view.ViewVersion;
import org.apache.spark.SparkException;
import org.apache.spark.sql.AnalysisException;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
Expand Down Expand Up @@ -1352,12 +1353,9 @@ public void createViewWithSubqueryExpressionUsingTempFunction() {
}

@TestTemplate
@SuppressWarnings("checkstyle:AssertThatThrownByWithMessageCheck")
public void createViewWithSubqueryExpressionInFilterThatIsRewritten()
throws NoSuchTableException {
assumeThat(catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE))
.as(
"Executing subquery expression with Hive fails due to an exception when instantiating the FileInputFormat")
.isNotEqualTo("hive");
insertRows(5);
String viewName = viewName("viewWithSubqueryExpression");
String sql =
Expand All @@ -1368,12 +1366,21 @@ public void createViewWithSubqueryExpressionInFilterThatIsRewritten()

assertThat(sql("SELECT * FROM %s", viewName)).hasSize(1).containsExactly(row(5));

String catalogType = catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE);
if (!catalogName.equals(SPARK_CATALOG)) {
sql("USE spark_catalog");

assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
if ("hive".equals(catalogType)) {
// The Hive view catalog shares its metastore with the default spark_catalog, so the
// Iceberg table IS resolvable there (unlike the in-memory/REST view catalogs) and does
// not raise AnalysisException. It cannot be read natively as a Hive table, so executing
// the raw SQL fails at execution time instead.
assertThatThrownBy(() -> sql(sql)).isInstanceOf(SparkException.class);
} else {
assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
}
}

// the underlying SQL in the View should be rewritten to have catalog & namespace
Expand All @@ -1383,11 +1390,8 @@ public void createViewWithSubqueryExpressionInFilterThatIsRewritten()
}

@TestTemplate
@SuppressWarnings("checkstyle:AssertThatThrownByWithMessageCheck")
public void createViewWithSubqueryExpressionInQueryThatIsRewritten() throws NoSuchTableException {
assumeThat(catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE))
.as(
"Executing subquery expression with Hive fails due to an exception when instantiating the FileInputFormat")
.isNotEqualTo("hive");
insertRows(3);
String viewName = viewName("viewWithSubqueryExpression");
String sql =
Expand All @@ -1399,12 +1403,21 @@ public void createViewWithSubqueryExpressionInQueryThatIsRewritten() throws NoSu
.hasSize(3)
.containsExactly(row(3), row(3), row(3));

String catalogType = catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE);
if (!catalogName.equals(SPARK_CATALOG)) {
sql("USE spark_catalog");

assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
if ("hive".equals(catalogType)) {
// The Hive view catalog shares its metastore with the default spark_catalog, so the
// Iceberg table IS resolvable there (unlike the in-memory/REST view catalogs) and does
// not raise AnalysisException. It cannot be read natively as a Hive table, so executing
// the raw SQL fails at execution time instead.
assertThatThrownBy(() -> sql(sql)).isInstanceOf(SparkException.class);
} else {
assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
}
}

// the underlying SQL in the View should be rewritten to have catalog & namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.iceberg.view.ViewProperties;
import org.apache.iceberg.view.ViewUtil;
import org.apache.iceberg.view.ViewVersion;
import org.apache.spark.SparkException;
import org.apache.spark.sql.AnalysisException;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
Expand Down Expand Up @@ -1352,12 +1353,9 @@ public void createViewWithSubqueryExpressionUsingTempFunction() {
}

@TestTemplate
@SuppressWarnings("checkstyle:AssertThatThrownByWithMessageCheck")
public void createViewWithSubqueryExpressionInFilterThatIsRewritten()
throws NoSuchTableException {
assumeThat(catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE))
.as(
"Executing subquery expression with Hive fails due to an exception when instantiating the FileInputFormat")
.isNotEqualTo("hive");
insertRows(5);
String viewName = viewName("viewWithSubqueryExpression");
String sql =
Expand All @@ -1368,12 +1366,21 @@ public void createViewWithSubqueryExpressionInFilterThatIsRewritten()

assertThat(sql("SELECT * FROM %s", viewName)).hasSize(1).containsExactly(row(5));

String catalogType = catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE);
if (!catalogName.equals(SPARK_CATALOG)) {
sql("USE spark_catalog");

assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
if ("hive".equals(catalogType)) {
// The Hive view catalog shares its metastore with the default spark_catalog, so the
// Iceberg table IS resolvable there (unlike the in-memory/REST view catalogs) and does
// not raise AnalysisException. It cannot be read natively as a Hive table, so executing
// the raw SQL fails at execution time instead.
assertThatThrownBy(() -> sql(sql)).isInstanceOf(SparkException.class);
} else {
assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
}
}

// the underlying SQL in the View should be rewritten to have catalog & namespace
Expand All @@ -1383,11 +1390,8 @@ public void createViewWithSubqueryExpressionInFilterThatIsRewritten()
}

@TestTemplate
@SuppressWarnings("checkstyle:AssertThatThrownByWithMessageCheck")
public void createViewWithSubqueryExpressionInQueryThatIsRewritten() throws NoSuchTableException {
assumeThat(catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE))
.as(
"Executing subquery expression with Hive fails due to an exception when instantiating the FileInputFormat")
.isNotEqualTo("hive");
insertRows(3);
String viewName = viewName("viewWithSubqueryExpression");
String sql =
Expand All @@ -1399,12 +1403,21 @@ public void createViewWithSubqueryExpressionInQueryThatIsRewritten() throws NoSu
.hasSize(3)
.containsExactly(row(3), row(3), row(3));

String catalogType = catalogConfig.get(CatalogUtil.ICEBERG_CATALOG_TYPE);
if (!catalogName.equals(SPARK_CATALOG)) {
sql("USE spark_catalog");

assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
if ("hive".equals(catalogType)) {
// The Hive view catalog shares its metastore with the default spark_catalog, so the
// Iceberg table IS resolvable there (unlike the in-memory/REST view catalogs) and does
// not raise AnalysisException. It cannot be read natively as a Hive table, so executing
// the raw SQL fails at execution time instead.
assertThatThrownBy(() -> sql(sql)).isInstanceOf(SparkException.class);
} else {
assertThatThrownBy(() -> sql(sql))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("The table or view `%s` cannot be found", tableName);
}
}

// the underlying SQL in the View should be rewritten to have catalog & namespace
Expand Down