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);
}
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations