bowenli86 commented on a change in pull request #10388: [FLINK-14912][Table] 
create, drop catalog functions through catalog manager
URL: https://github.com/apache/flink/pull/10388#discussion_r353456567
 
 

 ##########
 File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/functions/CatalogFunctionUtils.java
 ##########
 @@ -0,0 +1,77 @@
+/*
+ * 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.flink.table.functions;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.catalog.Catalog;
+import org.apache.flink.table.catalog.CatalogManager;
+import org.apache.flink.table.catalog.FunctionLanguage;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.util.StringUtils;
+
+import java.util.Optional;
+
+/**
+ * Utilities for catalog function.
+ */
+@Internal
+public final class CatalogFunctionUtils {
+
+       private CatalogFunctionUtils() {
+               // do not instantiate
+       }
+
+       /**
+        * Converts language string the FunctionLanguage.
+        * @param languageString  the language string from SQL parser
+        * @return supported FunctionLanguage otherwise raise 
UnsupportedOperationException.
+        */
+       public static FunctionLanguage parseLanguage(String languageString) {
+               if (StringUtils.isNullOrWhitespaceOnly(languageString)) {
+                       return FunctionLanguage.JAVA;
+               }
+
+               FunctionLanguage language = 
FunctionLanguage.valueOf(languageString);
+               if (language == null || 
language.equals(FunctionLanguage.PYTHON)) {
+                       throw new UnsupportedOperationException("Only function 
language JAVA and SCALA are supported for now.");
+               }
+
+               return language;
+       }
+
+       /**
+        * Look up catalog from catalog manager with function identifier.
+        * @param catalogManager the catalog manager to lookup
+        * @param functionIdentifier function identifier
+        * @param required whether catalog has to be exist
+        * @return return catalog otherwise throw UnsupportedOperationException.
+        */
+       public static Optional<Catalog> lookupCatalog(
+               CatalogManager catalogManager,
+               ObjectIdentifier functionIdentifier,
+               boolean required) {
+               Optional<Catalog> catalogOptional = 
catalogManager.getCatalog(functionIdentifier.getCatalogName());
+               if (!catalogOptional.isPresent() && required) {
 
 Review comment:
   `ignoreifnotexist` is for function, not catalog/db, 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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to