Skip to content

Commit

Permalink
Create table will fail with exception: Invalid table properties sort_…
Browse files Browse the repository at this point in the history
…columns, this is incorrect. Should throw correct exception like no schema is specified.
  • Loading branch information
jack86596 committed Jun 11, 2019
1 parent 9d02092 commit f4f33af
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class SDKwriterTestCase extends QueryTest with BeforeAndAfterEach {
|'carbondata' LOCATION
|'$writerPath' TBLPROPERTIES('sort_scope'='batch_sort') """.stripMargin)
}
assert(ex.message.contains("table properties are not supported for external table"))
assert(ex.message.contains("Table properties are not supported for external table"))
}

test("Read sdk writer output file and test without carbondata and carbonindex files should fail")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ class TestCreateTableIfNotExists extends QueryTest with BeforeAndAfterAll {
}
}

test("test create table without column specified") {
val exception = intercept[MalformedCarbonCommandException] {
sql("create table TableWithoutColumn stored by 'carbondata' tblproperties('sort_columns'='')")
}
assert(exception.getMessage.contains("Creating table without column(s) is not supported"))
}

override def afterAll {
sql("use default")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ object CommonUtil {

def validateTblProperties(tableProperties: Map[String, String], fields: Seq[Field]): Boolean = {
var isValid: Boolean = true
tableProperties.foreach {
case (key, value) =>
if (!validateFields(key, fields)) {
isValid = false
throw new MalformedCarbonCommandException(s"Invalid table properties ${ key }")
}
if (fields.nonEmpty) {
tableProperties.foreach {
case (key, value) =>
if (!validateFields(key, fields)) {
isValid = false
throw new MalformedCarbonCommandException(s"Invalid table properties $key")
}
}
}
isValid
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.spark.sql.parser

import scala.collection.JavaConverters._
import scala.collection.mutable

import org.antlr.v4.runtime.tree.TerminalNode
Expand Down Expand Up @@ -124,10 +123,13 @@ object CarbonSparkSqlParserUtil {
operationNotAllowed("Streaming is not allowed on partitioned table", partitionColumns)
}

if (!external && fields.isEmpty) {
throw new MalformedCarbonCommandException("Creating table without column(s) is not supported")
}
if (external && fields.isEmpty && tableProperties.nonEmpty) {
// as fields are always zero for external table, cannot validate table properties.
operationNotAllowed(
"table properties are not supported for external table", tablePropertyList)
"Table properties are not supported for external table", tablePropertyList)
}

// validate tblProperties
Expand Down

0 comments on commit f4f33af

Please sign in to comment.