xubo245 created CARBONDATA-3198:
-----------------------------------
Summary: ALTER ADD COLUMNS does not support datasource table with
type carbon
Key: CARBONDATA-3198
URL: https://issues.apache.org/jira/browse/CARBONDATA-3198
Project: CarbonData
Issue Type: Bug
Affects Versions: 1.5.1
Reporter: xubo245
Fix For: 1.5.2
code:
{code:java}
test("test add columns for table of using carbon") {
import spark.implicits._
val df = spark.sparkContext.parallelize(1 to 10)
.map(x => ("a" + x % 10, "b", x))
.toDF("c1", "c2", "number")
spark.sql("drop table if exists testparquet")
spark.sql("drop table if exists testformat")
// Saves dataframe to carbon file
df.write
.format("parquet").saveAsTable("testparquet")
spark.sql("create table carbon_table(c1 string, c2 string, number int)
using carbon")
spark.sql("insert into carbon_table select * from testparquet")
TestUtil.checkAnswer(spark.sql("select * from carbon_table where c1='a1'"),
spark.sql("select * from testparquet where c1='a1'"))
if (!spark.sparkContext.version.startsWith("2.1")) {
val mapSize = DataMapStoreManager.getInstance().getAllDataMaps.size()
DataMapStoreManager.getInstance()
.clearDataMaps(AbsoluteTableIdentifier.from(warehouse1 +
"/carbon_table"))
assert(mapSize > DataMapStoreManager.getInstance().getAllDataMaps.size())
}
spark.sql("select * from carbon_table").show()
spark.sql("ALTER TABLE carbon_table ADD COLUMNS (a1 INT, b1 STRING) ")
spark.sql("select * from carbon_table").show()
spark.sql("insert into carbon_table values('Bob','xu',12,1,'parquet')")
spark.sql("select * from carbon_table").show()
spark.sql("drop table if exists testparquet")
spark.sql("drop table if exists testformat")
}
{code}
exception:
{code:java}
2018-12-25 22:22:12 INFO ContextHandler:781 - Started
o.s.j.s.ServletContextHandler@51e0301d{/metrics/json,null,AVAILABLE,@Spark}
+---+---+------+
| c1| c2|number|
+---+---+------+
| a1| b| 1|
| a2| b| 2|
| a3| b| 3|
| a4| b| 4|
| a5| b| 5|
| a6| b| 6|
| a7| b| 7|
| a8| b| 8|
| a9| b| 9|
| a0| b| 10|
+---+---+------+
ALTER ADD COLUMNS does not support datasource table with type carbon.
You must drop and re-create the table for adding the new columns. Tables:
`carbon_table`
;
org.apache.spark.sql.AnalysisException:
ALTER ADD COLUMNS does not support datasource table with type carbon.
You must drop and re-create the table for adding the new columns. Tables:
`carbon_table`
;
at
org.apache.spark.sql.execution.command.AlterTableAddColumnsCommand.verifyAlterTableAddColumn(tables.scala:242)
at
org.apache.spark.sql.execution.command.AlterTableAddColumnsCommand.run(tables.scala:194)
at
org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult$lzycompute(commands.scala:70)
at
org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult(commands.scala:68)
at
org.apache.spark.sql.execution.command.ExecutedCommandExec.executeCollect(commands.scala:79)
at org.apache.spark.sql.Dataset$$anonfun$6.apply(Dataset.scala:190)
at org.apache.spark.sql.Dataset$$anonfun$6.apply(Dataset.scala:190)
at org.apache.spark.sql.Dataset$$anonfun$52.apply(Dataset.scala:3259)
at
org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:77)
at org.apache.spark.sql.Dataset.withAction(Dataset.scala:3258)
at org.apache.spark.sql.Dataset.<init>(Dataset.scala:190)
at org.apache.spark.sql.Dataset$.ofRows(Dataset.scala:75)
at org.apache.spark.sql.SparkSession.sql(SparkSession.scala:642)
at
org.apache.spark.sql.carbondata.datasource.SparkCarbonDataSourceTest$$anonfun$3.apply$mcV$sp(SparkCarbonDataSourceTest.scala:100)
at
org.apache.spark.sql.carbondata.datasource.SparkCarbonDataSourceTest$$anonfun$3.apply(SparkCarbonDataSourceTest.scala:80)
at
org.apache.spark.sql.carbondata.datasource.SparkCarbonDataSourceTest$$anonfun$3.apply(SparkCarbonDataSourceTest.scala:80)
at
org.scalatest.Transformer$$anonfun$apply$1.apply$mcV$sp(Transformer.scala:22)
at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.FunSuiteLike$$anon$1.apply(FunSuiteLike.scala:166)
at org.scalatest.Suite$class.withFixture(Suite.scala:1122)
at org.scalatest.FunSuite.withFixture(FunSuite.scala:1555)
at
org.scalatest.FunSuiteLike$class.invokeWithFixture$1(FunSuiteLike.scala:163)
at
org.scalatest.FunSuiteLike$$anonfun$runTest$1.apply(FunSuiteLike.scala:175)
at
org.scalatest.FunSuiteLike$$anonfun$runTest$1.apply(FunSuiteLike.scala:175)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
at org.scalatest.FunSuiteLike$class.runTest(FunSuiteLike.scala:175)
at org.scalatest.FunSuite.runTest(FunSuite.scala:1555)
at
org.scalatest.FunSuiteLike$$anonfun$runTests$1.apply(FunSuiteLike.scala:208)
at
org.scalatest.FunSuiteLike$$anonfun$runTests$1.apply(FunSuiteLike.scala:208)
at
org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:413)
at
org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:401)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
at
org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:396)
at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:483)
at org.scalatest.FunSuiteLike$class.runTests(FunSuiteLike.scala:208)
at org.scalatest.FunSuite.runTests(FunSuite.scala:1555)
at org.scalatest.Suite$class.run(Suite.scala:1424)
at
org.scalatest.FunSuite.org$scalatest$FunSuiteLike$$super$run(FunSuite.scala:1555)
at
org.scalatest.FunSuiteLike$$anonfun$run$1.apply(FunSuiteLike.scala:212)
at
org.scalatest.FunSuiteLike$$anonfun$run$1.apply(FunSuiteLike.scala:212)
at org.scalatest.SuperEngine.runImpl(Engine.scala:545)
at org.scalatest.FunSuiteLike$class.run(FunSuiteLike.scala:212)
at
org.apache.spark.sql.carbondata.datasource.SparkCarbonDataSourceTest.org$scalatest$BeforeAndAfterAll$$super$run(SparkCarbonDataSourceTest.scala:39)
at
org.scalatest.BeforeAndAfterAll$class.liftedTree1$1(BeforeAndAfterAll.scala:257)
at
org.scalatest.BeforeAndAfterAll$class.run(BeforeAndAfterAll.scala:256)
at
org.apache.spark.sql.carbondata.datasource.SparkCarbonDataSourceTest.run(SparkCarbonDataSourceTest.scala:39)
at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:55)
at
org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$3.apply(Runner.scala:2563)
at
org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$3.apply(Runner.scala:2557)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:2557)
at
org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1044)
at
org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1043)
at
org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:2722)
at
org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1043)
at org.scalatest.tools.Runner$.run(Runner.scala:883)
at org.scalatest.tools.Runner.run(Runner.scala)
at
org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:131)
at
org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)
Process finished with exit code 0
{code}
analysis:
org.apache.spark.sql.execution.command.AlterTableAddColumnsCommand#verifyAlterTableAddColumn
{code:java}
/**
* ALTER TABLE ADD COLUMNS command does not support temporary view/table,
* view, or datasource table with text, orc formats or external provider.
* For datasource table, it currently only supports parquet, json, csv.
*/
private def verifyAlterTableAddColumn(
conf: SQLConf,
catalog: SessionCatalog,
table: TableIdentifier): CatalogTable = {
val catalogTable = catalog.getTempViewOrPermanentTableMetadata(table)
if (catalogTable.tableType == CatalogTableType.VIEW) {
throw new AnalysisException(
s"""
|ALTER ADD COLUMNS does not support views.
|You must drop and re-create the views for adding the new columns.
Views: $table
""".stripMargin)
}
if (DDLUtils.isDatasourceTable(catalogTable)) {
DataSource.lookupDataSource(catalogTable.provider.get,
conf).newInstance() match {
// For datasource table, this command can only support the following
File format.
// TextFileFormat only default to one column "value"
// Hive type is already considered as hive serde table, so the logic
will not
// come in here.
case _: JsonFileFormat | _: CSVFileFormat | _: ParquetFileFormat =>
case s if s.getClass.getCanonicalName.endsWith("OrcFileFormat") =>
case s =>
throw new AnalysisException(
s"""
|ALTER ADD COLUMNS does not support datasource table with type $s.
|You must drop and re-create the table for adding the new
columns. Tables: $table
""".stripMargin)
}
}
catalogTable
}
}
{code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)