Search in sources :

Example 1 with InternalTypeHolder

use of com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder in project tispark by pingcap.

the class TiTableInfo method copyColumn.

private TiColumnInfo copyColumn(TiColumnInfo col) {
    DataType type = col.getType();
    InternalTypeHolder typeHolder = type.toTypeHolder();
    typeHolder.setFlag(type.getFlag() & (~DataType.PriKeyFlag));
    DataType newType = DataTypeFactory.of(typeHolder);
    return new TiColumnInfo(col.getId(), col.getName(), col.getOffset(), newType, col.getSchemaState(), col.getOriginDefaultValue(), col.getDefaultValue(), col.getDefaultValueBit(), col.getComment(), col.getVersion(), col.getGeneratedExprString(), col.isHidden()).copyWithoutPrimaryKey();
}
Also used : InternalTypeHolder(com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder) DataType(com.pingcap.tikv.types.DataType)

Example 2 with InternalTypeHolder

use of com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder in project tispark by pingcap.

the class TiKVScanAnalyzerTest method createTableWithPrefix.

private static TiTableInfo createTableWithPrefix() {
    InternalTypeHolder holder = new InternalTypeHolder(MySQLType.TypeVarchar.getTypeCode(), 0, // indicating a prefix type
    3, 0, "", "", ImmutableList.of());
    DataType typePrefix = DataTypeFactory.of(holder);
    return new MetaUtils.TableBuilder().name("testTable").addColumn("c1", IntegerType.INT, true).addColumn("c2", typePrefix).addColumn("c3", StringType.VARCHAR).addColumn("c4", IntegerType.INT).appendIndex("testIndex", ImmutableList.of("c1", "c2", "c3"), false).setPkHandle(true).build();
}
Also used : InternalTypeHolder(com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder) DataType(com.pingcap.tikv.types.DataType)

Example 3 with InternalTypeHolder

use of com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder in project tispark by pingcap.

the class TiKVScanAnalyzerTest method TestCoveringIndex.

@Test
public void TestCoveringIndex() {
    InternalTypeHolder holder = new InternalTypeHolder(MySQLType.TypeVarchar.getTypeCode(), 0, // indicating a prefix type
    3, 0, "", "", ImmutableList.of());
    Map<String, DataType> dataTypeMap = new HashMap<>();
    dataTypeMap.put("id", IntegerType.INT);
    dataTypeMap.put("a", IntegerType.INT);
    dataTypeMap.put("b", IntegerType.INT);
    dataTypeMap.put("c", IntegerType.INT);
    dataTypeMap.put("holder", DataTypeFactory.of(holder));
    Map<String, Integer> offsetMap = new HashMap<>();
    offsetMap.put("id", 0);
    offsetMap.put("a", 1);
    offsetMap.put("b", 2);
    offsetMap.put("c", 3);
    offsetMap.put("holder", 4);
    class test {

        private final String[] columnNames;

        private final String[] indexNames;

        private final int[] indexLens;

        private final boolean isCovering;

        private test(String[] col, String[] idx, int[] idxLen, boolean result) {
            columnNames = col;
            indexNames = idx;
            indexLens = idxLen;
            isCovering = result;
        }

        private String[] getColumnNames() {
            return columnNames;
        }

        private String[] getIndexNames() {
            return indexNames;
        }

        private int[] getIndexLens() {
            return indexLens;
        }
    }
    final test[] tests = { new test(new String[] { "a" }, new String[] { "a" }, new int[] { -1 }, true), new test(new String[] { "a" }, new String[] { "a", "b" }, new int[] { -1, -1 }, true), new test(new String[] { "a", "b" }, new String[] { "b", "a" }, new int[] { -1, -1 }, true), new test(new String[] { "a", "b" }, new String[] { "b", "c" }, new int[] { -1, -1 }, false), new test(new String[] { "holder", "b" }, new String[] { "holder", "b" }, new int[] { 50, -1 }, false), new test(new String[] { "a", "b" }, new String[] { "a", "c" }, new int[] { -1, -1 }, false), new test(new String[] { "id", "a" }, new String[] { "a", "b" }, new int[] { -1, -1 }, true) };
    TiKVScanAnalyzer scanBuilder = new TiKVScanAnalyzer();
    for (test t : tests) {
        List<TiColumnInfo> columns = new ArrayList<>();
        List<TiIndexColumn> indexCols = new ArrayList<>();
        boolean pkIsHandle = false;
        for (int i = 0; i < t.getColumnNames().length; i++) {
            String colName = t.getColumnNames()[i];
            if (colName.equals("id")) {
                pkIsHandle = true;
            }
            columns.add(new TiColumnInfo(offsetMap.get(colName), colName, i, dataTypeMap.get(colName), colName.equals("id")));
        }
        for (int i = 0; i < t.getIndexNames().length; i++) {
            String idxName = t.getIndexNames()[i];
            int idxLen = t.getIndexLens()[i];
            indexCols.add(new TiIndexColumn(CIStr.newCIStr(idxName), offsetMap.get(idxName), idxLen));
        }
        TiIndexInfo indexInfo = new TiIndexInfo(1, CIStr.newCIStr("test_idx"), CIStr.newCIStr("testTable"), ImmutableList.copyOf(indexCols), false, false, SchemaState.StatePublic.getStateCode(), "Test Index", IndexType.IndexTypeBtree.getTypeCode(), false, false);
        boolean isCovering = scanBuilder.isCoveringIndex(columns, indexInfo, pkIsHandle);
        assertEquals(t.isCovering, isCovering);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) InternalTypeHolder(com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder) TiIndexColumn(com.pingcap.tikv.meta.TiIndexColumn) DataType(com.pingcap.tikv.types.DataType) TiColumnInfo(com.pingcap.tikv.meta.TiColumnInfo) TiIndexInfo(com.pingcap.tikv.meta.TiIndexInfo) Test(org.junit.Test)

Example 4 with InternalTypeHolder

use of com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder in project tispark by pingcap.

the class DataTypeFactoryTest method mappingTest.

private void mappingTest(MySQLType type, Class<? extends DataType> cls) {
    InternalTypeHolder holder = createHolder(type);
    DataType dataType = DataTypeFactory.of(holder);
    assertEquals(type, dataType.getType());
    assertEquals(cls, dataType.getClass());
}
Also used : InternalTypeHolder(com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder)

Aggregations

InternalTypeHolder (com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder)4 DataType (com.pingcap.tikv.types.DataType)3 ByteString (com.google.protobuf.ByteString)1 TiColumnInfo (com.pingcap.tikv.meta.TiColumnInfo)1 TiIndexColumn (com.pingcap.tikv.meta.TiIndexColumn)1 TiIndexInfo (com.pingcap.tikv.meta.TiIndexInfo)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1