Skip to content

Commit

Permalink
[CARBONDATA-3116] set carbon.query.directQueryOnDataMap.enabled=true
Browse files Browse the repository at this point in the history
add
  • Loading branch information
xubo245 committed Dec 3, 2018
1 parent 382ce43 commit 00edfc1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
Expand Up @@ -17,6 +17,7 @@

package org.apache.carbondata.integration.spark.testsuite.preaggregate

import java.io.File
import java.util
import java.util.concurrent.{Callable, ExecutorService, Executors, TimeUnit}

Expand Down Expand Up @@ -486,6 +487,48 @@ class TestPreAggCreateCommand extends QueryTest with BeforeAndAfterAll {
executorService.shutdown()
}

test("support set carbon.query.directQueryOnDataMap.enabled=true") {
val rootPath = new File(this.getClass.getResource("/").getPath
+ "../../../..").getCanonicalPath
val testData = s"$rootPath/integration/spark-common-test/src/test/resources/sample.csv"
sql("drop table if exists mainTable")
sql(
s"""
| CREATE TABLE mainTable
| (id Int,
| name String,
| city String,
| age Int)
| STORED BY 'org.apache.carbondata.format'
""".stripMargin)

sql(
s"""
| LOAD DATA LOCAL INPATH '$testData'
| into table mainTable
""".stripMargin)

sql(
s"""
| create datamap preagg_sum on table mainTable
| using 'preaggregate'
| as select id,sum(age) from mainTable group by id
""".stripMargin)

CarbonProperties.getInstance()
.addProperty(CarbonCommonConstants.VALIDATE_DIRECT_QUERY_ON_DATAMAP, "true")

sql("set carbon.query.directQueryOnDataMap.enabled=true")
checkAnswer(sql("select count(*) from maintable_preagg_sum"), Row(4))
sql("set carbon.query.directQueryOnDataMap.enabled=false")
val exception: Exception = intercept[AnalysisException] {
sql("select count(*) from maintable_preagg_sum").collect()
}
assert(exception.getMessage.contains("Query On DataMap not supported"))
CarbonProperties.getInstance()
.addProperty(CarbonCommonConstants.VALIDATE_DIRECT_QUERY_ON_DATAMAP, "false")
}

class QueryTask(query: String) extends Callable[String] {
override def call(): String = {
var result = "SUCCESS"
Expand Down
5 changes: 5 additions & 0 deletions integration/spark2/pom.xml
Expand Up @@ -99,6 +99,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Expand Up @@ -119,16 +119,18 @@ class CarbonLateDecodeRule extends Rule[LogicalPlan] with PredicateHelper {
if (validateQuery && isPreAggDataMapExists) {
val carbonSessionInfo = ThreadLocalSessionInfo.getCarbonSessionInfo
if (null != carbonSessionInfo) {
val supportQueryOnDataMap = CarbonEnv.getThreadParam(
val supportQueryOnDataMap = CarbonProperties.getInstance.getProperty(
CarbonCommonConstants.SUPPORT_DIRECT_QUERY_ON_DATAMAP,
CarbonCommonConstants.SUPPORT_DIRECT_QUERY_ON_DATAMAP_DEFAULTVALUE).toBoolean
if (!supportQueryOnDataMap) {
isThrowException = true
}
}
}
if(isThrowException) {
throw new AnalysisException("Query On DataMap not supported")
if (isThrowException) {
throw new AnalysisException("Query On DataMap not supported because "
+ CarbonCommonConstants.SUPPORT_DIRECT_QUERY_ON_DATAMAP + " is false. " +
"Please change the value to true by set command or other if you want to query on DataMap.")
}
}

Expand Down

0 comments on commit 00edfc1

Please sign in to comment.