You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "YannByron (via GitHub)" <gi...@apache.org> on 2024/08/01 13:26:08 UTC

[PR] [spark] dataframe.write and insert sql syntax in byName mode [paimon]

YannByron opened a new pull request, #3871:
URL: https://github.com/apache/paimon/pull/3871

   <!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
   
   ### Purpose
   
   <!-- Linking this pull request to the issue -->
   Linked issue: close #xxx
   
   <!-- What is the purpose of the change -->
   
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   
   ### Documentation
   
   <!-- Does this change introduce a new feature -->
   


-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [spark] dataframe.write and insert sql syntax in byName mode [paimon]

Posted by "YannByron (via GitHub)" <gi...@apache.org>.
YannByron commented on code in PR #3871:
URL: https://github.com/apache/paimon/pull/3871#discussion_r1700268408


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/catalyst/analysis/PaimonAnalysis.scala:
##########
@@ -39,11 +40,17 @@ class PaimonAnalysis(session: SparkSession) extends Rule[LogicalPlan] {
   override def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsDown {
 
     case a @ PaimonV2WriteCommand(table, paimonTable)
-        if !schemaCompatible(
-          a.query.output.toStructType,
-          table.output.toStructType,
-          paimonTable.partitionKeys().asScala) =>
-      val newQuery = resolveQueryColumns(a.query, table.output)
+        if a.isByName && needsSchemaAdjustmentByName(a.query, table.output, paimonTable) =>
+      val newQuery = resolveQueryColumnsByName(a.query, table.output)
+      if (newQuery != a.query) {
+        Compatibility.withNewQuery(a, newQuery)
+      } else {
+        a
+      }
+
+    case a @ PaimonV2WriteCommand(table, paimonTable)
+        if !a.isByName && needsSchemaAdjustmentByPosition(a.query, table.output, paimonTable) =>

Review Comment:
   Prefer to separate these.



-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [spark] dataframe.write and insert sql syntax in byName mode [paimon]

Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on code in PR #3871:
URL: https://github.com/apache/paimon/pull/3871#discussion_r1700252843


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/catalyst/analysis/PaimonAnalysis.scala:
##########
@@ -39,11 +40,17 @@ class PaimonAnalysis(session: SparkSession) extends Rule[LogicalPlan] {
   override def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsDown {
 
     case a @ PaimonV2WriteCommand(table, paimonTable)
-        if !schemaCompatible(
-          a.query.output.toStructType,
-          table.output.toStructType,
-          paimonTable.partitionKeys().asScala) =>
-      val newQuery = resolveQueryColumns(a.query, table.output)
+        if a.isByName && needsSchemaAdjustmentByName(a.query, table.output, paimonTable) =>
+      val newQuery = resolveQueryColumnsByName(a.query, table.output)
+      if (newQuery != a.query) {
+        Compatibility.withNewQuery(a, newQuery)
+      } else {
+        a
+      }
+
+    case a @ PaimonV2WriteCommand(table, paimonTable)
+        if !a.isByName && needsSchemaAdjustmentByPosition(a.query, table.output, paimonTable) =>

Review Comment:
   Can these two match case merged



##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/catalyst/analysis/PaimonAnalysis.scala:
##########
@@ -57,6 +64,61 @@ class PaimonAnalysis(session: SparkSession) extends Rule[LogicalPlan] {
       PaimonMergeIntoResolver(merge, session)
   }
 
+  private def needsSchemaAdjustmentByName(
+      query: LogicalPlan,
+      targetAttrs: Seq[Attribute],
+      paimonTable: FileStoreTable): Boolean = {
+    val userSpecifiedNames = if (session.sessionState.conf.caseSensitiveAnalysis) {
+      query.output.map(a => (a.name, a)).toMap
+    } else {
+      CaseInsensitiveMap(query.output.map(a => (a.name, a)).toMap)
+    }
+    val specifiedTargetAttrs = targetAttrs.filter(col => userSpecifiedNames.contains(col.name))
+    !schemaCompatible(
+      specifiedTargetAttrs.toStructType,
+      query.output.toStructType,
+      paimonTable.partitionKeys().asScala)
+  }
+
+  private def resolveQueryColumnsByName(
+      query: LogicalPlan,
+      targetAttrs: Seq[Attribute]): LogicalPlan = {
+    val output = query.output
+    val project = targetAttrs.map {
+      attr =>
+        val outputAttr = output
+          .find(t => session.sessionState.conf.resolver(t.name, attr.name))
+          .getOrElse {
+            throw new RuntimeException("xxx")

Review Comment:
   update



-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [spark] dataframe.write and insert sql syntax in byName mode [paimon]

Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy merged PR #3871:
URL: https://github.com/apache/paimon/pull/3871


-- 
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: issues-unsubscribe@paimon.apache.org

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