You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by ra...@apache.org on 2016/08/01 10:05:33 UTC
[35/47] incubator-carbondata git commit: [CARBONDATA-114][Bug] While
describing/querying the complex type dimension precision not considered
(#879)
[CARBONDATA-114][Bug] While describing/querying the complex type dimension precision not considered (#879)
For decimal columns system was not able to maintain the scale/precision, always default precision has been taken which needs to be handled.
Project: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/commit/61b60746
Tree: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/tree/61b60746
Diff: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/diff/61b60746
Branch: refs/heads/master
Commit: 61b6074605445d5b9d92b31be85c3f4f9fc8a739
Parents: b3779e4
Author: sujith71955 <su...@gmail.com>
Authored: Fri Jul 29 06:01:27 2016 +0530
Committer: Venkata Ramana G <g....@gmail.com>
Committed: Fri Jul 29 06:01:27 2016 +0530
----------------------------------------------------------------------
.../spark/sql/CarbonDatasourceRelation.scala | 22 +++++++++++++-------
.../createtable/TestCreateTableSyntax.scala | 16 +++++++++++++-
2 files changed, 29 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/61b60746/integration/spark/src/main/scala/org/apache/spark/sql/CarbonDatasourceRelation.scala
----------------------------------------------------------------------
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/CarbonDatasourceRelation.scala b/integration/spark/src/main/scala/org/apache/spark/sql/CarbonDatasourceRelation.scala
index ed4e6cb..885ad49 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/CarbonDatasourceRelation.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/CarbonDatasourceRelation.scala
@@ -172,7 +172,7 @@ case class CarbonRelation(
childDim.getDataType.toString.toLowerCase match {
case "array" => s"array<${ getArrayChildren(childDim.getColName) }>"
case "struct" => s"struct<${ getStructChildren(childDim.getColName) }>"
- case dType => dType
+ case dType => addDecimalScaleAndPrecision(childDim, dType)
}
}).mkString(",")
}
@@ -188,7 +188,8 @@ case class CarbonRelation(
}:struct<${ metaData.carbonTable.getChildren(childDim.getColName)
.asScala.map(f => s"${ recursiveMethod(childDim.getColName, f) }").mkString(",")
}>"
- case dType => s"${ childDim.getColName.substring(dimName.length() + 1) }:${ dType }"
+ case dType => s"${ childDim.getColName
+ .substring(dimName.length() + 1) }:${ addDecimalScaleAndPrecision(childDim, dType) }"
}
}).mkString(",")
}
@@ -212,12 +213,7 @@ case class CarbonRelation(
case "struct" => CarbonMetastoreTypes
.toDataType(s"struct<${ getStructChildren(dim.getColName) }>")
case dType =>
- var dataType = dType
- if (dimval.getDataType == org.carbondata.core.carbon.metadata.datatype.DataType.DECIMAL) {
- dataType +=
- "(" + dimval.getColumnSchema.getPrecision + "," + dimval.getColumnSchema
- .getScale + ")"
- }
+ var dataType = addDecimalScaleAndPrecision(dimval, dType)
CarbonMetastoreTypes.toDataType(dataType)
}
@@ -257,6 +253,16 @@ case class CarbonRelation(
}
}
+ def addDecimalScaleAndPrecision(dimval: CarbonDimension, dataType: String): String = {
+ var dType = dataType
+ if (dimval.getDataType == org.carbondata.core.carbon.metadata.datatype.DataType.DECIMAL) {
+ dType +=
+ "(" + dimval.getColumnSchema.getPrecision + "," + dimval.getColumnSchema
+ .getScale + ")"
+ }
+ dType
+ }
+
private var tableStatusLastUpdateTime = 0L
private var sizeInBytesLocalValue = 0L
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/61b60746/integration/spark/src/test/scala/org/carbondata/spark/testsuite/createtable/TestCreateTableSyntax.scala
----------------------------------------------------------------------
diff --git a/integration/spark/src/test/scala/org/carbondata/spark/testsuite/createtable/TestCreateTableSyntax.scala b/integration/spark/src/test/scala/org/carbondata/spark/testsuite/createtable/TestCreateTableSyntax.scala
index 3868928..f62a3a1 100644
--- a/integration/spark/src/test/scala/org/carbondata/spark/testsuite/createtable/TestCreateTableSyntax.scala
+++ b/integration/spark/src/test/scala/org/carbondata/spark/testsuite/createtable/TestCreateTableSyntax.scala
@@ -21,7 +21,7 @@ package org.carbondata.spark.testsuite.createtable
import org.apache.spark.sql.common.util.CarbonHiveContext._
import org.apache.spark.sql.common.util.QueryTest
-
+import org.apache.spark.sql.{CarbonContext, Row}
import org.carbondata.spark.exception.MalformedCarbonCommandException
import org.scalatest.BeforeAndAfterAll
@@ -99,6 +99,20 @@ class TestCreateTableSyntax extends QueryTest with BeforeAndAfterAll {
sql("drop table if exists hivetable")
}
+ test("describe command carbon table for decimal scale and precision test") {
+ sql("create table carbontablePrecision(id int, name string, dept string, mobile array<string>, "+
+ "country string, salary decimal(10,6)) STORED BY 'org.apache.carbondata.format' " +
+ "TBLPROPERTIES('DICTIONARY_INCLUDE'='salary,id')")
+ checkAnswer(
+ sql("describe carbontablePrecision"),
+ Seq(Row("country","string",""),
+ Row("dept","string",""),Row("id","int",""),Row("mobile","array<string>",""),Row("name","string",""),
+ Row("salary","decimal(10,6)","")
+ )
+ )
+ sql("drop table if exists carbontablePrecision")
+ }
+
test("create carbon table without dimensions") {
try {
sql("create table carbontable(msr1 int, msr2 double, msr3 bigint, msr4 decimal)" +