Search in sources :

Example 1 with HBaseTableHandle

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();
    }
}
Also used : IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) HBasePageSinkProvider(io.hetu.core.plugin.hbase.query.HBasePageSinkProvider) ConnectorInsertTableHandle(io.prestosql.spi.connector.ConnectorInsertTableHandle) HBaseTransactionHandle(io.hetu.core.plugin.hbase.connector.HBaseTransactionHandle) Page(io.prestosql.spi.Page) VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock) Block(io.prestosql.spi.block.Block) IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) ConnectorPageSink(io.prestosql.spi.connector.ConnectorPageSink) HBaseTableHandle(io.hetu.core.plugin.hbase.connector.HBaseTableHandle) Test(org.testng.annotations.Test)

Example 2 with HBaseTableHandle

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);
    }
}
Also used : HBaseColumnHandle(io.hetu.core.plugin.hbase.connector.HBaseColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) HBaseColumnHandle(io.hetu.core.plugin.hbase.connector.HBaseColumnHandle) ArrayList(java.util.ArrayList) RecordSet(io.prestosql.spi.connector.RecordSet) HBaseTableHandle(io.hetu.core.plugin.hbase.connector.HBaseTableHandle) RecordPageSource(io.prestosql.spi.connector.RecordPageSource)

Example 3 with HBaseTableHandle

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);
}
Also used : HBaseColumnHandle(io.hetu.core.plugin.hbase.connector.HBaseColumnHandle) HBaseRecordSet(io.hetu.core.plugin.hbase.query.HBaseRecordSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HBaseSplit(io.hetu.core.plugin.hbase.split.HBaseSplit) Range(io.prestosql.spi.predicate.Range) HostAddress(io.prestosql.spi.HostAddress) ArrayList(java.util.ArrayList) List(java.util.List) HBaseTableHandle(io.hetu.core.plugin.hbase.connector.HBaseTableHandle) Test(org.testng.annotations.Test)

Example 4 with HBaseTableHandle

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()));
}
Also used : HBaseColumnHandle(io.hetu.core.plugin.hbase.connector.HBaseColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) HBaseTableHandle(io.hetu.core.plugin.hbase.connector.HBaseTableHandle)

Example 5 with HBaseTableHandle

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();
}
Also used : TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) TableName(org.apache.hadoop.hbase.TableName) IOException(java.io.IOException) HBaseTableHandle(io.hetu.core.plugin.hbase.connector.HBaseTableHandle)

Aggregations

HBaseTableHandle (io.hetu.core.plugin.hbase.connector.HBaseTableHandle)18 HBaseColumnHandle (io.hetu.core.plugin.hbase.connector.HBaseColumnHandle)5 Test (org.testng.annotations.Test)5 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)3 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)3 TableNotFoundException (io.prestosql.spi.connector.TableNotFoundException)3 HBaseRecordSet (io.hetu.core.plugin.hbase.query.HBaseRecordSet)2 HBaseSplit (io.hetu.core.plugin.hbase.split.HBaseSplit)2 HostAddress (io.prestosql.spi.HostAddress)2 ArrayList (java.util.ArrayList)2 HBaseTransactionHandle (io.hetu.core.plugin.hbase.connector.HBaseTransactionHandle)1 HBasePageSinkProvider (io.hetu.core.plugin.hbase.query.HBasePageSinkProvider)1 Page (io.prestosql.spi.Page)1 Block (io.prestosql.spi.block.Block)1 IntArrayBlock (io.prestosql.spi.block.IntArrayBlock)1 LongArrayBlock (io.prestosql.spi.block.LongArrayBlock)1 VariableWidthBlock (io.prestosql.spi.block.VariableWidthBlock)1 ConnectorInsertTableHandle (io.prestosql.spi.connector.ConnectorInsertTableHandle)1 ConnectorPageSink (io.prestosql.spi.connector.ConnectorPageSink)1 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)1