use of org.apache.carbondata.core.metadata.ColumnIdentifier in project carbondata by apache.
the class CarbonDictionarySortIndexReaderImplTest method read.
/**
* Test to read the data from dictionary sort index file
*
* @throws Exception
*/
@Test
public void read() throws Exception {
deleteStorePath();
CarbonTableIdentifier carbonTableIdentifier = new CarbonTableIdentifier("testSchema", "carbon", UUID.randomUUID().toString());
AbsoluteTableIdentifier absoluteTableIdentifier = AbsoluteTableIdentifier.from(storePath + "/testSchema/carbon", carbonTableIdentifier);
ColumnIdentifier columnIdentifier = new ColumnIdentifier("Name", null, null);
DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier = new DictionaryColumnUniqueIdentifier(absoluteTableIdentifier, columnIdentifier, columnIdentifier.getDataType());
CarbonDictionaryWriter dictionaryWriter = new CarbonDictionaryWriterImpl(dictionaryColumnUniqueIdentifier);
String metaFolderPath = storePath + File.separator + carbonTableIdentifier.getDatabaseName() + File.separator + carbonTableIdentifier.getTableName() + File.separator + "Metadata";
CarbonUtil.checkAndCreateFolder(metaFolderPath);
CarbonDictionarySortIndexWriter dictionarySortIndexWriter = new CarbonDictionarySortIndexWriterImpl(dictionaryColumnUniqueIdentifier);
List<int[]> expectedData = prepareExpectedData();
int[] data = expectedData.get(0);
for (int i = 0; i < data.length; i++) {
dictionaryWriter.write(String.valueOf(data[i]));
}
dictionaryWriter.close();
dictionaryWriter.commit();
List<Integer> sortIndex = Arrays.asList(ArrayUtils.toObject(expectedData.get(0)));
List<Integer> invertedSortIndex = Arrays.asList(ArrayUtils.toObject(expectedData.get(1)));
dictionarySortIndexWriter.writeSortIndex(sortIndex);
dictionarySortIndexWriter.writeInvertedSortIndex(invertedSortIndex);
dictionarySortIndexWriter.close();
CarbonDictionarySortIndexReader dictionarySortIndexReader = new CarbonDictionarySortIndexReaderImpl(dictionaryColumnUniqueIdentifier);
List<Integer> actualSortIndex = dictionarySortIndexReader.readSortIndex();
List<Integer> actualInvertedSortIndex = dictionarySortIndexReader.readInvertedSortIndex();
for (int i = 0; i < actualSortIndex.size(); i++) {
Assert.assertEquals(sortIndex.get(i), actualSortIndex.get(i));
Assert.assertEquals(invertedSortIndex.get(i), actualInvertedSortIndex.get(i));
}
}
use of org.apache.carbondata.core.metadata.ColumnIdentifier in project carbondata by apache.
the class ColumnIdentifierTest method equalsTestwithSimilarObject.
@Test
public void equalsTestwithSimilarObject() {
ColumnIdentifier columnIdentifierTest = new ColumnIdentifier("columnId", columnProperties, DataTypes.INT);
Boolean res = columnIdentifier.equals(columnIdentifierTest);
Assert.assertTrue(res);
}
use of org.apache.carbondata.core.metadata.ColumnIdentifier in project carbondata by apache.
the class ColumnIdentifierTest method equalsTestwithNullColumnId.
@Test
public void equalsTestwithNullColumnId() {
ColumnIdentifier columnIdentifierTest = new ColumnIdentifier(null, columnProperties, DataTypes.INT);
Boolean res = columnIdentifierTest.equals(columnIdentifier);
Assert.assertTrue(!res);
}
use of org.apache.carbondata.core.metadata.ColumnIdentifier in project carbondata by apache.
the class ColumnIdentifierTest method setup.
@BeforeClass
public static void setup() {
columnProperties = new HashMap<String, String>();
columnProperties.put("key", "value");
columnIdentifier = new ColumnIdentifier("columnId", columnProperties, DataTypes.INT);
}
use of org.apache.carbondata.core.metadata.ColumnIdentifier in project carbondata by apache.
the class AbstractDictionaryCacheTest method prepareWriterAndWriteData.
/**
* write dictionary data
*
* @param data
* @throws IOException
*/
protected void prepareWriterAndWriteData(List<String> data, String columnId) throws IOException {
ColumnIdentifier columnIdentifier = new ColumnIdentifier(columnId, null, null);
DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier = new DictionaryColumnUniqueIdentifier(identifier, columnIdentifier, columnIdentifier.getDataType());
CarbonDictionaryWriter carbonDictionaryWriter = new CarbonDictionaryWriterImpl(dictionaryColumnUniqueIdentifier);
CarbonUtil.checkAndCreateFolder(CarbonTablePath.getMetadataPath(identifier.getTablePath()));
List<byte[]> valueList = convertStringListToByteArray(data);
try {
carbonDictionaryWriter.write(valueList);
} finally {
carbonDictionaryWriter.close();
carbonDictionaryWriter.commit();
}
}
Aggregations