Skip to content

Commit ab04863

Browse files
author
Jacky Li
committedApr 25, 2016
Merge pull request apache#242 from QiangCai/dataloading
[Issue-232] add test case for incremental dictionary generation
2 parents 2408cb2 + c3cf0ea commit ab04863

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed
 

‎integration/spark/src/test/scala/org/apache/spark/sql/common/util/CarbonHiveContext.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import org.carbondata.core.constants.CarbonCommonConstants
2929
import org.carbondata.core.util.CarbonProperties
3030
import org.carbondata.integration.spark.load.CarbonLoaderUtil
3131

32-
class LocalSQLContext(hdfsCarbonBasePath: String)
32+
class LocalSQLContext(val hdfsCarbonBasePath: String)
3333
extends CarbonContext(new SparkContext(new SparkConf()
3434
.setAppName("CarbonSpark")
3535
.setMaster("local[2]")), hdfsCarbonBasePath) {

‎integration/spark/src/test/scala/org/carbondata/integration/spark/util/GlobalDictionaryUtilTestCase.scala

+43-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919
package org.carbondata.integration.spark.util
2020

2121
import java.io.File
22-
import org.carbondata.core.carbon.CarbonDataLoadSchema
23-
import org.carbondata.integration.spark.load.CarbonLoadModel
22+
2423
import org.apache.spark.sql.{ CarbonEnv, CarbonRelation }
2524
import org.apache.spark.sql.common.util.CarbonHiveContext
2625
import org.apache.spark.sql.common.util.CarbonHiveContext.sql
2726
import org.apache.spark.sql.common.util.QueryTest
27+
28+
import org.carbondata.core.cache.dictionary.DictionaryColumnUniqueIdentifier
29+
import org.carbondata.core.carbon.{ CarbonDataLoadSchema, CarbonTableIdentifier }
30+
import org.carbondata.core.constants.CarbonCommonConstants
31+
import org.carbondata.integration.spark.load.{ CarbonLoadModel, CarbonLoaderUtil }
32+
2833
import org.scalatest.BeforeAndAfterAll
2934

3035
/**
@@ -38,6 +43,7 @@ class GlobalDictionaryUtilTestCase extends QueryTest with BeforeAndAfterAll {
3843
var sampleRelation: CarbonRelation = _
3944
var dimSampleRelation: CarbonRelation = _
4045
var complexRelation: CarbonRelation = _
46+
var incrementalLoadTableRelation: CarbonRelation = _
4147
var filePath: String = _
4248
var pwd: String = _
4349
var dimFilePath: String = _
@@ -68,13 +74,20 @@ class GlobalDictionaryUtilTestCase extends QueryTest with BeforeAndAfterAll {
6874
} catch {
6975
case ex: Throwable => logError(ex.getMessage + "\r\n" + ex.getStackTraceString)
7076
}
77+
78+
try {
79+
sql("create cube incrementalLoadTable dimensions(deviceInformationId integer, channelsId string, ROMSize string, purchasedate string, mobile struct<imei string, imsi string>, MAC array<string>, locationinfo array<struct<ActiveAreaId integer, ActiveCountry string, ActiveProvince string, Activecity string, ActiveDistrict string, ActiveStreet string>>, proddate struct<productionDate string,activeDeactivedate array<string>>) measures(gamePointId numeric,contractNumber numeric) OPTIONS (PARTITIONER [CLASS = 'org.carbondata.integration.spark.partition.api.impl.SampleDataPartitionerImpl' ,COLUMNS= (deviceInformationId) , PARTITION_COUNT=1] )")
80+
} catch {
81+
case ex: Throwable => logError(ex.getMessage + "\r\n" + ex.getStackTraceString)
82+
}
7183
}
7284

7385
def buildRelation() = {
7486
val catalog = CarbonEnv.getInstance(CarbonHiveContext).carbonCatalog
7587
sampleRelation = catalog.lookupRelation1(Option("default"), "sample", None)(CarbonHiveContext).asInstanceOf[CarbonRelation]
7688
dimSampleRelation = catalog.lookupRelation1(Option("default"), "dimSample", None)(CarbonHiveContext).asInstanceOf[CarbonRelation]
7789
complexRelation = catalog.lookupRelation1(Option("default"), "complextypes", None)(CarbonHiveContext).asInstanceOf[CarbonRelation]
90+
incrementalLoadTableRelation= catalog.lookupRelation1(Option("default"), "incrementalLoadTable", None)(CarbonHiveContext).asInstanceOf[CarbonRelation]
7891
}
7992

8093
def buildCarbonLoadModel(relation: CarbonRelation,
@@ -94,8 +107,8 @@ class GlobalDictionaryUtilTestCase extends QueryTest with BeforeAndAfterAll {
94107
carbonLoadModel.setDimFolderPath(dimensionFilePath)
95108
carbonLoadModel.setCsvHeader(header)
96109
carbonLoadModel.setCsvDelimiter(",")
97-
carbonLoadModel.setComplexDelimiterLevel1("$")
98-
carbonLoadModel.setComplexDelimiterLevel2(":")
110+
carbonLoadModel.setComplexDelimiterLevel1("\\$")
111+
carbonLoadModel.setComplexDelimiterLevel2("\\:")
99112
carbonLoadModel
100113
}
101114

@@ -105,11 +118,23 @@ class GlobalDictionaryUtilTestCase extends QueryTest with BeforeAndAfterAll {
105118
buildTable
106119
buildRelation
107120
}
121+
122+
def checkDictionary(relation: CarbonRelation, columnName: String, value: String){
123+
val table = relation.cubeMeta.carbonTable
124+
val dimension = table.getDimensionByName(table.getFactTableName, columnName)
125+
val tableIdentifier = new CarbonTableIdentifier(table.getDatabaseName,table.getFactTableName)
126+
val columnIdentifier = new DictionaryColumnUniqueIdentifier(tableIdentifier,
127+
dimension.getColumnId)
128+
val dict = CarbonLoaderUtil.getDictionary(columnIdentifier,
129+
CarbonHiveContext.hdfsCarbonBasePath)
130+
assert( dict.getSurrogateKey(value)!= CarbonCommonConstants.INVALID_SURROGATE_KEY)
131+
}
108132

109133
test("[issue-80]Global Dictionary Generation") {
110134

111135
var carbonLoadModel = buildCarbonLoadModel(sampleRelation, filePath, null, null)
112136
GlobalDictionaryUtil.generateGlobalDictionary(CarbonHiveContext, carbonLoadModel, sampleRelation.cubeMeta.dataPath, false)
137+
113138
// test for dimension table
114139
// TODO - Need to fill and send the dimension table data as per new DimensionRelation in CarbonDataLoadModel
115140
// carbonLoadModel = buildCarbonLoadModel(dimSampleRelation, filePath, dimFilePath, null)
@@ -120,5 +145,18 @@ class GlobalDictionaryUtilTestCase extends QueryTest with BeforeAndAfterAll {
120145
val header = "deviceInformationId,channelsId,ROMSize,purchasedate,mobile,MAC,locationinfo,proddate,gamePointId,contractNumber"
121146
var carbonLoadModel = buildCarbonLoadModel(complexRelation, complexfilePath2, null, header)
122147
GlobalDictionaryUtil.generateGlobalDictionary(CarbonHiveContext, carbonLoadModel, sampleRelation.cubeMeta.dataPath, false)
123-
}
148+
}
149+
150+
test("[Issue-232]Issue in incremental data load for dictionary generation"){
151+
val header = "deviceInformationId,channelsId,ROMSize,purchasedate,mobile,MAC,locationinfo,proddate,gamePointId,contractNumber"
152+
// load 1
153+
var carbonLoadModel = buildCarbonLoadModel(incrementalLoadTableRelation, complexfilePath1, null, header)
154+
GlobalDictionaryUtil.generateGlobalDictionary(CarbonHiveContext, carbonLoadModel, sampleRelation.cubeMeta.dataPath, false)
155+
checkDictionary(incrementalLoadTableRelation, "deviceInformationId" ,"100010")
156+
157+
// load 2
158+
carbonLoadModel = buildCarbonLoadModel(incrementalLoadTableRelation, complexfilePath2, null, header)
159+
GlobalDictionaryUtil.generateGlobalDictionary(CarbonHiveContext, carbonLoadModel, sampleRelation.cubeMeta.dataPath, false)
160+
checkDictionary(incrementalLoadTableRelation, "deviceInformationId" ,"100077")
161+
}
124162
}

0 commit comments

Comments
 (0)
Please sign in to comment.