You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@carbondata.apache.org by GitBox <gi...@apache.org> on 2020/02/24 16:57:40 UTC
[GitHub] [carbondata] jackylk commented on a change in pull request #3634:
[CARBONDATA-3720] Support alter table scenario for new insert into flow
jackylk commented on a change in pull request #3634: [CARBONDATA-3720] Support alter table scenario for new insert into flow
URL: https://github.com/apache/carbondata/pull/3634#discussion_r383388985
##########
File path: integration/spark/src/main/scala/org/apache/spark/sql/execution/command/management/CarbonInsertIntoCommand.scala
##########
@@ -449,67 +443,48 @@ case class CarbonInsertIntoCommand(databaseNameOp: Option[String],
}
}
- private def isAlteredSchema(tableSchema: TableSchema): Boolean = {
- if (tableInfo.getFactTable.getSchemaEvolution != null) {
- tableInfo
- .getFactTable
- .getSchemaEvolution
- .getSchemaEvolutionEntryList.asScala.exists(entry =>
- (entry.getAdded != null && entry.getAdded.size() > 0) ||
- (entry.getRemoved != null && entry.getRemoved.size() > 0)
- )
- } else {
- false
- }
- }
-
def getReArrangedIndexAndSelectedSchema(
tableInfo: TableInfo,
partitionColumnSchema: mutable.Buffer[ColumnSchema]): (Seq[Int], Seq[ColumnSchema]) = {
var reArrangedIndex: Seq[Int] = Seq()
var selectedColumnSchema: Seq[ColumnSchema] = Seq()
- var complexChildCount: Int = 0
var partitionIndex: Seq[Int] = Seq()
- val columnSchema = tableInfo.getFactTable.getListOfColumns.asScala
+ val internalOrderColumns: util.ArrayList[CarbonColumn] = new util.ArrayList[CarbonColumn]()
+ internalOrderColumns.addAll(table.getVisibleDimensions)
+ internalOrderColumns.addAll(table.getVisibleMeasures)
+ val columnSchema = internalOrderColumns.asScala.map(col => col.getColumnSchema)
val partitionColumnNames = if (partitionColumnSchema != null) {
partitionColumnSchema.map(x => x.getColumnName).toSet
} else {
null
}
- // get invisible column indexes, alter table scenarios can have it before or after new column
- // dummy measure will have ordinal -1 and it is invisible, ignore that column.
- // alter table old columns are just invisible columns with proper ordinal
- val invisibleIndex = columnSchema.filter(col => col.isInvisible && col.getSchemaOrdinal != -1)
- .map(col => col.getSchemaOrdinal)
- columnSchema.filterNot(col => col.isInvisible).foreach {
+ var createOrderColumns = table.getCreateOrderColumn.asScala
+ val createOrderMap = mutable.Map[String, Int]()
+ var createOrderPosition = 0
+ if (partitionColumnNames != null) {
+ // For alter table drop/add column scenarios, partition column may not be in the end.
+ // Need to keep it in the end.
+ createOrderColumns = createOrderColumns.filterNot(col =>
+ partitionColumnNames.contains(col.getColumnSchema.getColumnName)) ++
+ createOrderColumns.filter(col =>
+ partitionColumnNames.contains(col.getColumnSchema.getColumnName))
+ }
+ for (col: CarbonColumn <- createOrderColumns) {
Review comment:
use foreach instead
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services