You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by GitBox <gi...@apache.org> on 2022/10/31 06:18:48 UTC

[GitHub] [incubator-kyuubi] waywtdcc commented on a diff in pull request #3718: [KYUUBI #3717] Support flink engine see primary keys

waywtdcc commented on code in PR #3718:
URL: https://github.com/apache/incubator-kyuubi/pull/3718#discussion_r1009062230


##########
externals/kyuubi-flink-sql-engine/src/main/scala/org/apache/kyuubi/engine/flink/operation/GetPrimaryKeys.scala:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.kyuubi.engine.flink.operation
+
+import java.util.Collections
+
+import scala.collection.JavaConverters._
+
+import org.apache.commons.lang3.StringUtils
+import org.apache.flink.table.api.{DataTypes, ResultKind}
+import org.apache.flink.table.api.bridge.java.internal.StreamTableEnvironmentImpl
+import org.apache.flink.table.catalog.{Column, UniqueConstraint}
+import org.apache.flink.types.Row
+
+import org.apache.kyuubi.engine.flink.result.ResultSet
+import org.apache.kyuubi.operation.meta.ResultSetSchemaConstant._
+import org.apache.kyuubi.session.Session
+
+class GetPrimaryKeys(
+    session: Session,
+    catalogNameOrEmpty: String,
+    schemaNameOrEmpty: String,
+    tableName: String)
+  extends FlinkOperation(session) {
+
+  override protected def runInternal(): Unit = {
+    try {
+      val tableEnv = sessionContext.getExecutionContext.getTableEnvironment
+
+      val catalogName =
+        if (StringUtils.isEmpty(catalogNameOrEmpty)) tableEnv.getCurrentCatalog
+        else catalogNameOrEmpty
+      val catalog = tableEnv.getCatalog(catalogName).get()
+
+      val schemaName =
+        if (StringUtils.isEmpty(schemaNameOrEmpty)) catalog.getDefaultDatabase
+        else schemaNameOrEmpty
+
+      val flinkTable = tableEnv.from(s"`$catalogName`.`$schemaName`.`$tableName`")
+
+      val resolvedSchema = flinkTable.getResolvedSchema
+      val uniqueConstraint = resolvedSchema.getPrimaryKey.orElse(
+        UniqueConstraint.primaryKey("null_pri", Collections.emptyList()))

Review Comment:
   Thanks for your reviews. I have modified 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: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org