use of io.hetu.core.plugin.hbase.connector.HBaseTableHandle in project hetu-core by openlookeng.
the class TestHBase method testPageSink.
/**
* testPageSink
*/
@Test
public void testPageSink() {
HBasePageSinkProvider hpsp = new HBasePageSinkProvider(hconn);
HBaseTableHandle insertHandler = new HBaseTableHandle("hbase", "test_table", 0, hconn.getTable("hbase.test_table").getColumns(), hconn.getTable("hbase.test_table").getSerializerClassName(), Optional.of("test_table"), OptionalLong.empty());
if (insertHandler instanceof ConnectorInsertTableHandle) {
ConnectorPageSink cps = hpsp.createPageSink(new HBaseTransactionHandle(), session, (ConnectorInsertTableHandle) insertHandler);
long completedBytes = cps.getCompletedBytes();
long sysMemUsage = cps.getSystemMemoryUsage();
long cpuNanos = cps.getValidationCpuNanos();
assertTrue(cpuNanos >= 0);
assertTrue(sysMemUsage >= 0);
assertTrue(completedBytes >= 0);
int[] offsets = { 0, 4 };
Block rowkey = new VariableWidthBlock(1, TestSliceUtils.createSlice("0001"), offsets, Optional.empty());
int[] offset2 = { 0, 5 };
Block name = new VariableWidthBlock(1, TestSliceUtils.createSlice("name2"), offset2, Optional.empty());
long[] longs = new long[1];
longs[0] = 12;
Block age = new LongArrayBlock(1, Optional.empty(), longs);
int[] ints = new int[1];
ints[0] = 17832;
Block gender = new IntArrayBlock(1, Optional.empty(), ints);
Block columnT = new LongArrayBlock(1, Optional.empty(), longs);
Page page = new Page(rowkey, name, age, gender, columnT);
assertEquals(NOT_BLOCKED, cps.appendPage(page));
cps.abort();
}
}
use of io.hetu.core.plugin.hbase.connector.HBaseTableHandle in project hetu-core by openlookeng.
the class HBasePageSourceProvider method createPageSource.
@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, ConnectorTableHandle table, List<ColumnHandle> columns) {
// if delete rows, we should replace $rowId -> real rowkey name
List<ColumnHandle> columnsReplaceRowKey = new ArrayList<>();
columns.forEach(ch -> {
if (Constants.HBASE_ROWID_NAME.equals(ch.getColumnName())) {
if (ch instanceof HBaseColumnHandle && table instanceof HBaseTableHandle) {
HBaseColumnHandle rowColumnHandle = (HBaseColumnHandle) ch;
columnsReplaceRowKey.add(new HBaseColumnHandle(((HBaseTableHandle) table).getRowId(), rowColumnHandle.getFamily(), rowColumnHandle.getQualifier(), rowColumnHandle.getType(), rowColumnHandle.getOrdinal(), rowColumnHandle.getComment(), rowColumnHandle.isIndexed()));
}
} else {
columnsReplaceRowKey.add(ch);
}
});
RecordSet recordSet = recordSetProvider.getRecordSet(transactionHandle, session, split, table, columnsReplaceRowKey);
HBaseRecordSet hbaseRecordSet = null;
if (recordSet instanceof HBaseRecordSet) {
hbaseRecordSet = (HBaseRecordSet) recordSet;
}
if (columnsReplaceRowKey.stream().anyMatch(ch -> (ch instanceof HBaseColumnHandle) && (table instanceof HBaseTableHandle) && ((HBaseColumnHandle) ch).getOrdinal() == ((HBaseTableHandle) table).getRowIdOrdinal())) {
return new HBaseUpdatablePageSource(hbaseRecordSet, hbaseConnection);
} else {
return new RecordPageSource(recordSet);
}
}
use of io.hetu.core.plugin.hbase.connector.HBaseTableHandle in project hetu-core by openlookeng.
the class TestQuery method testHBaseRecordSetGetFiltersFromDomains.
/**
* testHBaseRecordSetGetFiltersFromDomains
*/
@Test
public void testHBaseRecordSetGetFiltersFromDomains() {
List<HBaseColumnHandle> list = new ArrayList<>();
list.add(TestUtils.createHBaseColumnRowId("rowkey"));
HBaseTableHandle tableHandle = new HBaseTableHandle("hbase", "test_table", "rowkey", false, "io.hetu.core.plugin.hbase.utils.serializers.StringRowSerializer", Optional.of("test_table"), "", null, list, 0, OptionalLong.empty());
// case ABOVE
Map<Integer, List<Range>> ranges = new HashMap<>();
long startRow = 1;
long endRow = 12345678;
List<Range> range = new ArrayList<>();
range.add(new Range(Marker.above(BIGINT, startRow), Marker.below(BIGINT, endRow)));
ranges.put(0, range);
HBaseSplit hBasesplit = new HBaseSplit("rowkey", tableHandle, new ArrayList<HostAddress>(1), "1", "12345678", ranges, -1, false, null);
HBaseRecordSet rSet = new HBaseRecordSet(hconn, session, hBasesplit, tableHandle, list);
rSet.getFiltersFromDomains(ranges);
// List<Range> is null
ranges.clear();
ranges.put(0, null);
rSet.getFiltersFromDomains(ranges);
// case EXACTLY
range.clear();
ranges.clear();
long exactly = 12345678;
range.add(Range.equal(BIGINT, exactly));
ranges.put(0, range);
rSet.getFiltersFromDomains(ranges);
// other case
range.add(Range.range(BIGINT, exactly, true, exactly * 2, true));
ranges.put(1, range);
list.add(TestUtils.createHBaseColumnHandle("a", "f_a", "q_a", 1));
HBaseRecordSet rSet2Column = new HBaseRecordSet(hconn, session, hBasesplit, tableHandle, list);
rSet2Column.getFiltersFromDomains(ranges);
}
use of io.hetu.core.plugin.hbase.connector.HBaseTableHandle in project hetu-core by openlookeng.
the class HBaseConnectorMetadata method applyFilter.
@Override
public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(ConnectorSession session, ConnectorTableHandle connectorTableHandle, Constraint constraint) {
HBaseTableHandle tableHandle;
if (connectorTableHandle instanceof HBaseTableHandle) {
tableHandle = (HBaseTableHandle) connectorTableHandle;
} else {
return Optional.empty();
}
TupleDomain<ColumnHandle> oldDomain = tableHandle.getConstraint();
TupleDomain<ColumnHandle> newDomain = oldDomain.intersect(constraint.getSummary());
if (oldDomain.equals(newDomain)) {
return Optional.empty();
}
HBaseTableHandle newTableHandle = new HBaseTableHandle(tableHandle.getSchema(), tableHandle.getTable(), tableHandle.getRowId(), tableHandle.isExternal(), tableHandle.getSerializerClassName(), tableHandle.getHbaseTableName(), tableHandle.getFullTableName(), newDomain, tableHandle.getColumns(), tableHandle.getRowIdOrdinal(), tableHandle.getLimit());
return Optional.of(new ConstraintApplicationResult<>(newTableHandle, constraint.getSummary()));
}
use of io.hetu.core.plugin.hbase.connector.HBaseTableHandle in project hetu-core by openlookeng.
the class HBaseConnectorMetadata method executeDelete.
@Override
public OptionalLong executeDelete(ConnectorSession session, ConnectorTableHandle deleteHandle) {
if (deleteHandle instanceof HBaseTableHandle) {
HBaseTableHandle hBaseTableHandle = (HBaseTableHandle) deleteHandle;
HBaseTable table = hbaseConn.getTable(hBaseTableHandle.getFullTableName());
if (table == null) {
throw new TableNotFoundException(hBaseTableHandle.toSchemaTableName());
}
try {
TableName tableName = TableName.valueOf(table.getHbaseTableName().get());
hbaseConn.getHbaseAdmin().disableTable(tableName);
hbaseConn.getHbaseAdmin().truncateTable(tableName, false);
} catch (IOException e) {
LOG.error("HBase delete table failed... cause by %s", e);
}
}
return OptionalLong.empty();
}
Aggregations