Skip to content

Commit

Permalink
[CARBONDATA-2811][BloomDataMap] Add query test case using search mode…
Browse files Browse the repository at this point in the history
… on table with bloom filter

This closes #2598
  • Loading branch information
kevinjmh authored and QiangCai committed Sep 11, 2018
1 parent 73a5885 commit 7c827c0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Expand Up @@ -830,6 +830,8 @@ class BloomCoarseGrainDataMapFunctionSuite extends QueryTest with BeforeAndAfte
sql("drop table if exists test_rcd").collect()
CarbonProperties.getInstance().addProperty(CarbonCommonConstants.BLOCKLET_SIZE,
CarbonCommonConstants.BLOCKLET_SIZE_DEFAULT_VAL)
CarbonProperties.getInstance().addProperty(CarbonV3DataFormatConstants.BLOCKLET_SIZE_IN_MB,
CarbonV3DataFormatConstants.BLOCKLET_SIZE_IN_MB_DEFAULT_VALUE)
}

/**
Expand Down
Expand Up @@ -32,6 +32,7 @@ import org.apache.carbondata.core.datamap.status.DataMapStatusManager
import org.apache.carbondata.core.util.CarbonProperties

class BloomCoarseGrainDataMapSuite extends QueryTest with BeforeAndAfterAll with BeforeAndAfterEach {
val carbonSession = sqlContext.sparkSession.asInstanceOf[CarbonSession]
val bigFile = s"$resourcesPath/bloom_datamap_input_big.csv"
val smallFile = s"$resourcesPath/bloom_datamap_input_small.csv"
val normalTable = "carbon_normal"
Expand Down Expand Up @@ -251,6 +252,61 @@ class BloomCoarseGrainDataMapSuite extends QueryTest with BeforeAndAfterAll with
sql(s"DROP TABLE IF EXISTS $bloomDMSampleTable")
}

test("test using search mode to query tabel with bloom datamap") {
sql(
s"""
| CREATE TABLE $normalTable(id INT, name STRING, city STRING, age INT,
| s1 STRING, s2 STRING, s3 STRING, s4 STRING, s5 STRING, s6 STRING, s7 STRING, s8 STRING)
| STORED BY 'carbondata' TBLPROPERTIES('table_blocksize'='128')
| """.stripMargin)
sql(
s"""
| CREATE TABLE $bloomDMSampleTable(id INT, name STRING, city STRING, age INT,
| s1 STRING, s2 STRING, s3 STRING, s4 STRING, s5 STRING, s6 STRING, s7 STRING, s8 STRING)
| STORED BY 'carbondata' TBLPROPERTIES('table_blocksize'='128')
| """.stripMargin)

// load two segments
(1 to 2).foreach { i =>
sql(
s"""
| LOAD DATA LOCAL INPATH '$bigFile' INTO TABLE $normalTable
| OPTIONS('header'='false')
""".stripMargin)
sql(
s"""
| LOAD DATA LOCAL INPATH '$bigFile' INTO TABLE $bloomDMSampleTable
| OPTIONS('header'='false')
""".stripMargin)
}

sql(
s"""
| CREATE DATAMAP $dataMapName ON TABLE $bloomDMSampleTable
| USING 'bloomfilter'
| DMProperties('INDEX_COLUMNS'='city,id', 'BLOOM_SIZE'='640000')
""".stripMargin)
checkExistence(sql(s"SHOW DATAMAP ON TABLE $bloomDMSampleTable"), true, dataMapName)

// get answer before search mode is enable
val expectedAnswer1 = sql(s"select * from $normalTable where id = 1").collect()
val expectedAnswer2 = sql(s"select * from $normalTable where city in ('city_999')").collect()

carbonSession.startSearchMode()
assert(carbonSession.isSearchModeEnabled)

checkAnswer(
sql(s"select * from $bloomDMSampleTable where id = 1"), expectedAnswer1)
checkAnswer(
sql(s"select * from $bloomDMSampleTable where city in ('city_999')"), expectedAnswer2)

carbonSession.stopSearchMode()
assert(!carbonSession.isSearchModeEnabled)

sql(s"DROP TABLE IF EXISTS $normalTable")
sql(s"DROP TABLE IF EXISTS $bloomDMSampleTable")
}

ignore("test create bloom datamap with DEFERRED REBUILD, query hit datamap") {
sql(
s"""
Expand Down Expand Up @@ -848,6 +904,10 @@ class BloomCoarseGrainDataMapSuite extends QueryTest with BeforeAndAfterAll with
}

override protected def afterAll(): Unit = {
// in case of search mode test case failed, stop search mode again
if (carbonSession.isSearchModeEnabled) {
carbonSession.stopSearchMode()
}
deleteFile(bigFile)
deleteFile(smallFile)
sql(s"DROP TABLE IF EXISTS $normalTable")
Expand Down

0 comments on commit 7c827c0

Please sign in to comment.