Search in sources :

Example 6 with ColumnIdentifier

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));
    }
}
Also used : CarbonDictionaryWriterImpl(org.apache.carbondata.core.writer.CarbonDictionaryWriterImpl) CarbonDictionarySortIndexWriter(org.apache.carbondata.core.writer.sortindex.CarbonDictionarySortIndexWriter) DictionaryColumnUniqueIdentifier(org.apache.carbondata.core.cache.dictionary.DictionaryColumnUniqueIdentifier) CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) AbsoluteTableIdentifier(org.apache.carbondata.core.metadata.AbsoluteTableIdentifier) CarbonDictionarySortIndexWriterImpl(org.apache.carbondata.core.writer.sortindex.CarbonDictionarySortIndexWriterImpl) ColumnIdentifier(org.apache.carbondata.core.metadata.ColumnIdentifier) CarbonDictionaryWriter(org.apache.carbondata.core.writer.CarbonDictionaryWriter) Test(org.junit.Test)

Example 7 with ColumnIdentifier

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);
}
Also used : ColumnIdentifier(org.apache.carbondata.core.metadata.ColumnIdentifier) Test(org.junit.Test)

Example 8 with ColumnIdentifier

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);
}
Also used : ColumnIdentifier(org.apache.carbondata.core.metadata.ColumnIdentifier) Test(org.junit.Test)

Example 9 with ColumnIdentifier

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);
}
Also used : ColumnIdentifier(org.apache.carbondata.core.metadata.ColumnIdentifier) BeforeClass(org.junit.BeforeClass)

Example 10 with ColumnIdentifier

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();
    }
}
Also used : CarbonDictionaryWriterImpl(org.apache.carbondata.core.writer.CarbonDictionaryWriterImpl) ColumnIdentifier(org.apache.carbondata.core.metadata.ColumnIdentifier) CarbonDictionaryWriter(org.apache.carbondata.core.writer.CarbonDictionaryWriter)

Aggregations

ColumnIdentifier (org.apache.carbondata.core.metadata.ColumnIdentifier)22 DictionaryColumnUniqueIdentifier (org.apache.carbondata.core.cache.dictionary.DictionaryColumnUniqueIdentifier)11 CarbonTableIdentifier (org.apache.carbondata.core.metadata.CarbonTableIdentifier)7 CarbonDictionaryWriter (org.apache.carbondata.core.writer.CarbonDictionaryWriter)7 Dictionary (org.apache.carbondata.core.cache.dictionary.Dictionary)6 CarbonDictionaryWriterImpl (org.apache.carbondata.core.writer.CarbonDictionaryWriterImpl)6 ArrayList (java.util.ArrayList)5 AbsoluteTableIdentifier (org.apache.carbondata.core.metadata.AbsoluteTableIdentifier)5 CarbonDictionarySortIndexWriter (org.apache.carbondata.core.writer.sortindex.CarbonDictionarySortIndexWriter)5 CarbonDictionarySortIndexWriterImpl (org.apache.carbondata.core.writer.sortindex.CarbonDictionarySortIndexWriterImpl)5 Test (org.junit.Test)5 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)4 BeforeClass (org.junit.BeforeClass)4 BufferedReader (java.io.BufferedReader)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Cache (org.apache.carbondata.core.cache.Cache)3 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)3 CarbonDictionarySortInfo (org.apache.carbondata.core.writer.sortindex.CarbonDictionarySortInfo)3