Search in sources :

Example 1 with HBaseColumnHandle

use of io.hetu.core.plugin.hbase.connector.HBaseColumnHandle in project hetu-core by openlookeng.

the class StringRowSerializer method deserialize.

/**
 * deserialize
 *
 * @param result Entry to deserialize
 * @param defaultValue defaultValue
 */
@Override
public void deserialize(Result result, String defaultValue) {
    if (!columnValues.containsKey(rowIdName)) {
        columnValues.put(rowIdName, new String(result.getRow(), Charset.forName("UTF-8")));
    }
    String family;
    String qualifer;
    String value = null;
    byte[] bytes;
    for (HBaseColumnHandle hc : columnHandles) {
        if (!hc.getName().equals(rowIdName)) {
            family = hc.getFamily().get();
            qualifer = hc.getQualifier().get();
            bytes = result.getValue(family.getBytes(UTF_8), qualifer.getBytes(UTF_8));
            if (bytes == null) {
                value = defaultValue;
            } else {
                Charset cs = Charset.forName("UTF-8");
                CharsetDecoder coder = cs.newDecoder();
                try {
                    value = coder.decode(ByteBuffer.wrap(bytes)).toString();
                } catch (CharacterCodingException e) {
                    LOG.error("bytes decode to string error, cause by %s", e.getMessage());
                    LOG.error("Error message: " + e.getStackTrace());
                }
            }
            columnValues.put(familyQualifierColumnMap.get(family).get(qualifer), value);
        }
    }
}
Also used : HBaseColumnHandle(io.hetu.core.plugin.hbase.connector.HBaseColumnHandle) CharsetDecoder(java.nio.charset.CharsetDecoder) Charset(java.nio.charset.Charset) CharacterCodingException(java.nio.charset.CharacterCodingException)

Example 2 with HBaseColumnHandle

use of io.hetu.core.plugin.hbase.connector.HBaseColumnHandle 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 HBaseColumnHandle

use of io.hetu.core.plugin.hbase.connector.HBaseColumnHandle in project hetu-core by openlookeng.

the class HBaseRecordSet method getFiltersFromDomains.

/**
 * transform domain to filters
 *
 * @param domainMap domains
 * @return filterList
 */
public FilterList getFiltersFromDomains(Map<Integer, List<Range>> domainMap) {
    FilterList andFilters = new FilterList(FilterList.Operator.MUST_PASS_ALL);
    // select count(*) / count(rowKey) / rowKey from table_xxx;
    if ((this.columnHandles.size() == 1 && this.columnHandles.get(0).getColumnName().equals(this.split.getRowKeyName())) || this.columnHandles.size() == 0) {
        andFilters.addFilter(new FirstKeyOnlyFilter());
        andFilters.addFilter(new KeyOnlyFilter());
    }
    if (domainMap == null || domainMap.isEmpty()) {
        return andFilters;
    }
    domainMap.entrySet().stream().forEach(entry -> {
        Integer columnId = entry.getKey();
        List<Range> ranges = entry.getValue();
        HBaseColumnHandle columnHandle = columnHandles.stream().filter(col -> checkPredicateType(col) && columnId == col.getOrdinal()).findAny().orElse(null);
        if (ranges == null || columnHandle == null) {
            return;
        }
        // inFilters: put "="
        List<Filter> inFilters = new ArrayList<>();
        // filters: put "<" "<=" ">" ">="
        List<Filter> filters = new ArrayList<>();
        getFiltersFromRanges(ranges, columnHandle, andFilters, inFilters, filters);
        // operate is IN / =
        if (inFilters.size() != 0) {
            FilterList columnFilter = new FilterList(FilterList.Operator.MUST_PASS_ONE, inFilters);
            andFilters.addFilter(columnFilter);
        }
        // != 3 become "id < 3" or "id > 3"
        if (ranges.size() > 1 && filters.size() != 0) {
            FilterList orFilter = new FilterList(FilterList.Operator.MUST_PASS_ONE, filters);
            andFilters.addFilter(orFilter);
        }
        if (ranges.size() <= 1 && filters.size() != 0) {
            FilterList andFilter = new FilterList(filters);
            andFilters.addFilter(andFilter);
        }
        // operator IS NULL
        if (ranges.isEmpty()) {
            boolean isKey = (this.split.getRowKeyName().equals(columnHandle.getName()));
            andFilters.addFilter(columnOrKeyFilter(columnHandle, null, CompareOperator.EQUAL, isKey));
        }
    });
    return andFilters;
}
Also used : HBaseColumnHandle(io.hetu.core.plugin.hbase.connector.HBaseColumnHandle) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) KeyOnlyFilter(org.apache.hadoop.hbase.filter.KeyOnlyFilter) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) Filter(org.apache.hadoop.hbase.filter.Filter) KeyOnlyFilter(org.apache.hadoop.hbase.filter.KeyOnlyFilter) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) ArrayList(java.util.ArrayList) FilterList(org.apache.hadoop.hbase.filter.FilterList) Range(io.prestosql.spi.predicate.Range)

Example 4 with HBaseColumnHandle

use of io.hetu.core.plugin.hbase.connector.HBaseColumnHandle in project hetu-core by openlookeng.

the class HBaseTable method parseHbaseTableToJson.

/**
 * parseHbaseTableToJson
 *
 * @return JSONObject
 * @throws JSONException JSONException
 */
public JSONObject parseHbaseTableToJson() throws JSONException {
    JSONObject jo = new JSONObject();
    jo.put("schema", schema);
    jo.put("external", external);
    jo.put("rowIdOrdinal", rowIdOrdinal);
    jo.put("serializerClassName", serializerClassName);
    jo.put("indexed", indexed);
    jo.put("rowId", rowId);
    jo.put("table", table);
    jo.put("indexColumns", indexColumns);
    jo.put("hbaseTableName", hbaseTableName.orElse(""));
    jo.put("splitByChar", splitByChar.orElse(""));
    JSONArray jac = new JSONArray();
    JSONObject joc;
    for (HBaseColumnHandle hc : columns) {
        joc = hc.parseToJson();
        jac.put(joc);
    }
    jo.accumulate("columns", jac);
    return jo;
}
Also used : HBaseColumnHandle(io.hetu.core.plugin.hbase.connector.HBaseColumnHandle) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray)

Example 5 with HBaseColumnHandle

use of io.hetu.core.plugin.hbase.connector.HBaseColumnHandle in project hetu-core by openlookeng.

the class HetuHBaseMetastore method getHBaseTableFromHetuMetastore.

private HBaseTable getHBaseTableFromHetuMetastore(String catalog, String schema, String table) {
    TableEntity tableEntity = hetuMetastore.getTable(catalog, schema, table).orElse(null);
    if (tableEntity == null) {
        return null;
    }
    Map<String, ColumnHandle> columnsMap = new HashMap<>();
    List<HBaseColumnHandle> columns = new ArrayList<>();
    for (ColumnEntity entity : tableEntity.getColumns()) {
        Map<String, String> columnParam = entity.getParameters();
        HBaseColumnHandle columnHandle = new HBaseColumnHandle(entity.getName(), Optional.ofNullable(columnParam.get(Constants.S_FAMILY)), Optional.ofNullable(columnParam.get(Constants.S_QUALIFIER)), Utils.createTypeByName(entity.getType()), Integer.parseInt(columnParam.get(Constants.S_ORDINAL)), entity.getComment(), Constants.S_TRUE.equals(columnParam.get(Constants.S_INDEXED).toLowerCase(Locale.ENGLISH)));
        columns.add(columnHandle);
        columnsMap.put(entity.getName(), columnHandle);
    }
    Map<String, String> tableParam = tableEntity.getParameters();
    HBaseTable hBaseTable = new HBaseTable(tableEntity.getDatabaseName(), tableEntity.getName(), columns, tableParam.get(Constants.S_ROWID), Constants.S_TRUE.equals(tableParam.get(Constants.S_EXTERNAL).toLowerCase(Locale.ENGLISH)), Optional.ofNullable(tableParam.get(Constants.S_SERIALIZER_CLASS_NAME)), Optional.ofNullable(tableParam.get(Constants.S_INDEX_COLUMNS)), Optional.ofNullable(tableParam.get(Constants.S_HBASE_TABLE_NAME)), Optional.ofNullable(tableParam.get(Constants.S_SPLIT_BY_CHAR)));
    hBaseTable.setColumnsToMap(columnsMap);
    return hBaseTable;
}
Also used : HBaseColumnHandle(io.hetu.core.plugin.hbase.connector.HBaseColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) HBaseColumnHandle(io.hetu.core.plugin.hbase.connector.HBaseColumnHandle) ColumnEntity(io.prestosql.spi.metastore.model.ColumnEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TableEntity(io.prestosql.spi.metastore.model.TableEntity)

Aggregations

HBaseColumnHandle (io.hetu.core.plugin.hbase.connector.HBaseColumnHandle)13 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)6 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)5 Range (io.prestosql.spi.predicate.Range)4 List (java.util.List)4 HBaseTableHandle (io.hetu.core.plugin.hbase.connector.HBaseTableHandle)3 HostAddress (io.prestosql.spi.HostAddress)2 ColumnEntity (io.prestosql.spi.metastore.model.ColumnEntity)2 TableEntity (io.prestosql.spi.metastore.model.TableEntity)2 Domain (io.prestosql.spi.predicate.Domain)2 TupleDomain (io.prestosql.spi.predicate.TupleDomain)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 JSONArray (org.codehaus.jettison.json.JSONArray)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Test (org.testng.annotations.Test)2 Logger (io.airlift.log.Logger)1 Slice (io.airlift.slice.Slice)1 HBaseConnection (io.hetu.core.plugin.hbase.connector.HBaseConnection)1