forked from apache/carbondata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the file_name in carbonindex exactly.
- Loading branch information
Showing
5 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
.../test/scala/org/apache/carbondata/spark/testsuite/dataload/TestDataLoadWithFileName.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package org.apache.carbondata.spark.testsuite.dataload | ||
|
||
import java.io.{File, FilenameFilter} | ||
|
||
import org.apache.carbondata.core.constants.CarbonCommonConstants | ||
import org.apache.carbondata.core.reader.CarbonIndexFileReader | ||
import org.apache.carbondata.core.util.CarbonProperties | ||
import org.apache.carbondata.core.util.path.CarbonTablePath | ||
import org.apache.spark.sql.common.util.QueryTest | ||
import org.scalatest.BeforeAndAfterAll | ||
|
||
class TestDataLoadWithFileName extends QueryTest with BeforeAndAfterAll { | ||
var originVersion = "" | ||
|
||
override def beforeAll() { | ||
originVersion = | ||
CarbonProperties.getInstance.getProperty(CarbonCommonConstants.CARBON_DATA_FILE_VERSION) | ||
} | ||
|
||
test("Test the file_name in carbonindex with v1 format") { | ||
CarbonProperties.getInstance.addProperty(CarbonCommonConstants.CARBON_DATA_FILE_VERSION, "1") | ||
sql("DROP TABLE IF EXISTS test_table_v1") | ||
sql( | ||
""" | ||
| CREATE TABLE test_table_v1(id int, name string, city string, age int) | ||
| STORED BY 'org.apache.carbondata.format' | ||
""".stripMargin) | ||
val testData = s"$resourcesPath/sample.csv" | ||
sql(s"LOAD DATA LOCAL INPATH '$testData' into table test_table_v1") | ||
val indexReader = new CarbonIndexFileReader() | ||
val carbonIndexPaths = new File(s"$storeLocation/default/test_table_v1/Fact/Part0/Segment_0/") | ||
.listFiles(new FilenameFilter { | ||
override def accept(dir: File, name: String): Boolean = { | ||
name.endsWith(CarbonTablePath.getCarbonIndexExtension) | ||
} | ||
}) | ||
for (carbonIndexPath <- carbonIndexPaths) { | ||
indexReader.openThriftReader(carbonIndexPath.getCanonicalPath) | ||
assert(indexReader.readIndexHeader().getVersion === 1) | ||
while (indexReader.hasNext) { | ||
val readBlockIndexInfo = indexReader.readBlockIndexInfo() | ||
assert(readBlockIndexInfo.getFile_name.startsWith(storeLocation)) | ||
} | ||
} | ||
} | ||
|
||
test("Test the file_name in carbonindex with v2 format") { | ||
CarbonProperties.getInstance.addProperty(CarbonCommonConstants.CARBON_DATA_FILE_VERSION, "2") | ||
sql("DROP TABLE IF EXISTS test_table_v2") | ||
sql( | ||
""" | ||
| CREATE TABLE test_table_v2(id int, name string, city string, age int) | ||
| STORED BY 'org.apache.carbondata.format' | ||
""".stripMargin) | ||
val testData = s"$resourcesPath/sample.csv" | ||
sql(s"LOAD DATA LOCAL INPATH '$testData' into table test_table_v2") | ||
val indexReader = new CarbonIndexFileReader() | ||
val carbonIndexPaths = new File(s"$storeLocation/default/test_table_v2/Fact/Part0/Segment_0/") | ||
.listFiles(new FilenameFilter { | ||
override def accept(dir: File, name: String): Boolean = { | ||
name.endsWith(CarbonTablePath.getCarbonIndexExtension) | ||
} | ||
}) | ||
for (carbonIndexPath <- carbonIndexPaths) { | ||
indexReader.openThriftReader(carbonIndexPath.getCanonicalPath) | ||
assert(indexReader.readIndexHeader().getVersion === 2) | ||
while (indexReader.hasNext) { | ||
val readBlockIndexInfo = indexReader.readBlockIndexInfo() | ||
assert(readBlockIndexInfo.getFile_name.startsWith(storeLocation)) | ||
} | ||
} | ||
} | ||
|
||
test("Test the file_name in carbonindex with v3 format") { | ||
CarbonProperties.getInstance.addProperty(CarbonCommonConstants.CARBON_DATA_FILE_VERSION, "3") | ||
sql("DROP TABLE IF EXISTS test_table_v3") | ||
sql( | ||
""" | ||
| CREATE TABLE test_table_v3(id int, name string, city string, age int) | ||
| STORED BY 'org.apache.carbondata.format' | ||
""".stripMargin) | ||
val testData = s"$resourcesPath/sample.csv" | ||
sql(s"LOAD DATA LOCAL INPATH '$testData' into table test_table_v3") | ||
val indexReader = new CarbonIndexFileReader() | ||
val carbonIndexPaths = new File(s"$storeLocation/default/test_table_v3/Fact/Part0/Segment_0/") | ||
.listFiles(new FilenameFilter { | ||
override def accept(dir: File, name: String): Boolean = { | ||
name.endsWith(CarbonTablePath.getCarbonIndexExtension) | ||
} | ||
}) | ||
for (carbonIndexPath <- carbonIndexPaths) { | ||
indexReader.openThriftReader(carbonIndexPath.getCanonicalPath) | ||
assert(indexReader.readIndexHeader().getVersion === 3) | ||
while (indexReader.hasNext) { | ||
val readBlockIndexInfo = indexReader.readBlockIndexInfo() | ||
assert(readBlockIndexInfo.getFile_name.startsWith(storeLocation)) | ||
} | ||
} | ||
} | ||
|
||
override protected def afterAll() { | ||
sql("DROP TABLE IF EXISTS test_table_v1") | ||
sql("DROP TABLE IF EXISTS test_table_v2") | ||
sql("DROP TABLE IF EXISTS test_table_v3") | ||
CarbonProperties.getInstance.addProperty(CarbonCommonConstants.CARBON_DATA_FILE_VERSION, | ||
originVersion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters