From 9393a9430dadad614ee2a3f72890809d8a343dc4 Mon Sep 17 00:00:00 2001 From: Zouxxyy Date: Tue, 10 Sep 2024 19:01:35 +0800 Subject: [PATCH] [spark] Add error message when sessionCatalog is null (#4161) --- .../apache/paimon/spark/SparkGenericCatalog.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkGenericCatalog.java b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkGenericCatalog.java index ae85e799581b..12407f2614ff 100644 --- a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkGenericCatalog.java +++ b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkGenericCatalog.java @@ -66,6 +66,7 @@ import static org.apache.paimon.options.CatalogOptions.WAREHOUSE; import static org.apache.paimon.spark.SparkCatalogOptions.CREATE_UNDERLYING_SESSION_CATALOG; import static org.apache.paimon.spark.SparkCatalogOptions.DEFAULT_DATABASE; +import static org.apache.paimon.utils.Preconditions.checkNotNull; /* This file is based on source code from the Iceberg Project (http://iceberg.apache.org/), licensed by the Apache * Software Foundation (ASF) under the Apache License, Version 2.0. See the NOTICE file distributed with this work for @@ -338,16 +339,24 @@ public void setDelegateCatalog(CatalogPlugin delegate) { } } + private CatalogPlugin getDelegateCatalog() { + checkNotNull( + sessionCatalog, + "Delegated SessionCatalog is missing, '%s' can only be used with 'spark_catalog'.", + SparkGenericCatalog.class.getName()); + return sessionCatalog; + } + private TableCatalog asTableCatalog() { - return (TableCatalog) sessionCatalog; + return (TableCatalog) getDelegateCatalog(); } private SupportsNamespaces asNamespaceCatalog() { - return (SupportsNamespaces) sessionCatalog; + return (SupportsNamespaces) getDelegateCatalog(); } private FunctionCatalog asFunctionCatalog() { - return (FunctionCatalog) sessionCatalog; + return (FunctionCatalog) getDelegateCatalog(); } @Override