19
19
package org .carbondata .integration .spark .util
20
20
21
21
import java .io .File
22
- import org .carbondata .core .carbon .CarbonDataLoadSchema
23
- import org .carbondata .integration .spark .load .CarbonLoadModel
22
+
24
23
import org .apache .spark .sql .{ CarbonEnv , CarbonRelation }
25
24
import org .apache .spark .sql .common .util .CarbonHiveContext
26
25
import org .apache .spark .sql .common .util .CarbonHiveContext .sql
27
26
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
+
28
33
import org .scalatest .BeforeAndAfterAll
29
34
30
35
/**
@@ -38,6 +43,7 @@ class GlobalDictionaryUtilTestCase extends QueryTest with BeforeAndAfterAll {
38
43
var sampleRelation : CarbonRelation = _
39
44
var dimSampleRelation : CarbonRelation = _
40
45
var complexRelation : CarbonRelation = _
46
+ var incrementalLoadTableRelation : CarbonRelation = _
41
47
var filePath : String = _
42
48
var pwd : String = _
43
49
var dimFilePath : String = _
@@ -68,13 +74,20 @@ class GlobalDictionaryUtilTestCase extends QueryTest with BeforeAndAfterAll {
68
74
} catch {
69
75
case ex : Throwable => logError(ex.getMessage + " \r\n " + ex.getStackTraceString)
70
76
}
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
+ }
71
83
}
72
84
73
85
def buildRelation () = {
74
86
val catalog = CarbonEnv .getInstance(CarbonHiveContext ).carbonCatalog
75
87
sampleRelation = catalog.lookupRelation1(Option (" default" ), " sample" , None )(CarbonHiveContext ).asInstanceOf [CarbonRelation ]
76
88
dimSampleRelation = catalog.lookupRelation1(Option (" default" ), " dimSample" , None )(CarbonHiveContext ).asInstanceOf [CarbonRelation ]
77
89
complexRelation = catalog.lookupRelation1(Option (" default" ), " complextypes" , None )(CarbonHiveContext ).asInstanceOf [CarbonRelation ]
90
+ incrementalLoadTableRelation= catalog.lookupRelation1(Option (" default" ), " incrementalLoadTable" , None )(CarbonHiveContext ).asInstanceOf [CarbonRelation ]
78
91
}
79
92
80
93
def buildCarbonLoadModel (relation : CarbonRelation ,
@@ -94,8 +107,8 @@ class GlobalDictionaryUtilTestCase extends QueryTest with BeforeAndAfterAll {
94
107
carbonLoadModel.setDimFolderPath(dimensionFilePath)
95
108
carbonLoadModel.setCsvHeader(header)
96
109
carbonLoadModel.setCsvDelimiter(" ," )
97
- carbonLoadModel.setComplexDelimiterLevel1(" $" )
98
- carbonLoadModel.setComplexDelimiterLevel2(" :" )
110
+ carbonLoadModel.setComplexDelimiterLevel1(" \\ $" )
111
+ carbonLoadModel.setComplexDelimiterLevel2(" \\ :" )
99
112
carbonLoadModel
100
113
}
101
114
@@ -105,11 +118,23 @@ class GlobalDictionaryUtilTestCase extends QueryTest with BeforeAndAfterAll {
105
118
buildTable
106
119
buildRelation
107
120
}
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
+ }
108
132
109
133
test(" [issue-80]Global Dictionary Generation" ) {
110
134
111
135
var carbonLoadModel = buildCarbonLoadModel(sampleRelation, filePath, null , null )
112
136
GlobalDictionaryUtil .generateGlobalDictionary(CarbonHiveContext , carbonLoadModel, sampleRelation.cubeMeta.dataPath, false )
137
+
113
138
// test for dimension table
114
139
// TODO - Need to fill and send the dimension table data as per new DimensionRelation in CarbonDataLoadModel
115
140
// carbonLoadModel = buildCarbonLoadModel(dimSampleRelation, filePath, dimFilePath, null)
@@ -120,5 +145,18 @@ class GlobalDictionaryUtilTestCase extends QueryTest with BeforeAndAfterAll {
120
145
val header = " deviceInformationId,channelsId,ROMSize,purchasedate,mobile,MAC,locationinfo,proddate,gamePointId,contractNumber"
121
146
var carbonLoadModel = buildCarbonLoadModel(complexRelation, complexfilePath2, null , header)
122
147
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
+ }
124
162
}
0 commit comments