Github user manishgupta88 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2109#discussion_r178787300
--- Diff:
integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/preaaggregate/PreAggregateTableHelper.scala
---
@@ -62,8 +63,25 @@ case class PreAggregateTableHelper(
val df = sparkSession.sql(updatedQuery)
val fieldRelationMap =
PreAggregateUtil.validateActualSelectPlanAndGetAttributes(
df.logicalPlan, queryString)
+ val partitionInfo = parentTable.getPartitionInfo
val fields = fieldRelationMap.keySet.toSeq
val tableProperties = mutable.Map[String, String]()
+ val parentPartitionColumns = if (parentTable.isHivePartitionTable) {
+ partitionInfo.getColumnSchemaList.asScala.map(_.getColumnName)
+ } else {
+ Seq()
+ }
+ // Generate child table partition columns in the same order as the
parent table.
+ val partitionerFields = fieldRelationMap.collect {
+ case (field, dataMapField) if parentPartitionColumns
+ .exists(parentCol =>
+
parentCol.equals(dataMapField.columnTableRelationList.get.head.parentColumnName)
&&
+ dataMapField.aggregateFunction.isEmpty) =>
+ (PartitionerField(field.name.get,
+ field.dataType,
+ field.columnComment), parentPartitionColumns
+
.indexOf(dataMapField.columnTableRelationList.get.head.parentColumnName))
+ }.toSeq.sortBy(_._2).map(_._1)
--- End diff --
I think sortBy and map operation is not required here as already the child
datamap ordering is according to the parent table partition column ordering
---