use of com.pingcap.tikv.types.DataType in project tispark by pingcap.
the class Codec method decodeOne.
public static Object decodeOne(byte[] colData) {
if (colData.length <= 1) {
throw new CodecException("invalid encoded column data, length <=1");
}
int flag = colData[0];
DataType tp;
switch(flag) {
case INT_FLAG:
case UINT_FLAG:
case VARINT_FLAG:
case UVARINT_FLAG:
tp = IntegerType.BIGINT;
break;
case FLOATING_FLAG:
tp = RealType.DOUBLE;
break;
case BYTES_FLAG:
case COMPACT_BYTES_FLAG:
tp = BytesType.TEXT;
break;
case DECIMAL_FLAG:
tp = DecimalType.DECIMAL;
break;
case DURATION_FLAG:
tp = TimeType.TIME;
break;
case JSON_FLAG:
tp = JsonType.JSON;
break;
default:
throw new CodecException("Unknown type");
}
return tp.decode(new CodecDataInput(colData));
}
use of com.pingcap.tikv.types.DataType in project tispark by pingcap.
the class TiColumnInfo method copyWithoutPrimaryKey.
TiColumnInfo copyWithoutPrimaryKey() {
InternalTypeHolder typeHolder = type.toTypeHolder();
typeHolder.setFlag(type.getFlag() & (~TiColumnInfo.PK_MASK));
DataType newType = DataTypeFactory.of(typeHolder);
return new TiColumnInfo(this.id, this.name, this.offset, newType, this.schemaState, this.originDefaultValue, this.defaultValue, this.defaultValueBit, this.comment, this.version, this.generatedExprString, this.hidden);
}
use of com.pingcap.tikv.types.DataType in project tispark by pingcap.
the class CoprocessorIterator method getRowIterator.
/**
* Build a DAGIterator from TiDAGRequest and region tasks to get rows
*
* <p>When we are preforming a scan request using coveringIndex, {@link
* com.pingcap.tidb.tipb.IndexScan} should be used to read index rows. In other circumstances,
* {@link com.pingcap.tidb.tipb.TableScan} is used to scan table rows.
*
* @param req TiDAGRequest built
* @param regionTasks a list or RegionTask each contains a task on a single region
* @param session TiSession
* @return a DAGIterator to be processed
*/
public static CoprocessorIterator<Row> getRowIterator(TiDAGRequest req, List<RegionTask> regionTasks, TiSession session) {
TiDAGRequest dagRequest = req.copy();
// set encode type to TypeDefault because currently, only
// CoprocessorIterator<TiChunk> support TypeChunk and TypeCHBlock encode type
dagRequest.setEncodeType(EncodeType.TypeDefault);
return new DAGIterator<Row>(dagRequest.buildTableScan(), regionTasks, session, SchemaInfer.create(dagRequest), dagRequest.getPushDownType(), dagRequest.getStoreType(), dagRequest.getStartTs().getVersion()) {
@Override
public Row next() {
return rowReader.readRow(schemaInfer.getTypes().toArray(new DataType[0]));
}
};
}
use of com.pingcap.tikv.types.DataType in project tispark by pingcap.
the class DefaultRowReader method readRow.
public Row readRow(DataType[] dataTypes) {
int length = dataTypes.length;
Row row = ObjectRowImpl.create(length);
for (int i = 0; i < length; i++) {
DataType type = dataTypes[i];
if (type.isNextNull(cdi)) {
cdi.readUnsignedByte();
row.setNull(i);
} else {
row.set(i, type, type.decode(cdi));
}
}
return row;
}
use of com.pingcap.tikv.types.DataType 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);
}
}
Aggregations