public Map<String,String> toMap() { return getOptions().getAllKeyValus(); }
public int hashCode() { return Objects.hashCode(getDataFormat(), getOptions()); }
@Override public JsonElement serialize(TableMeta src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.addProperty("store", src.getDataFormat()); jsonObj.add("options", context.serialize(src.getOptions(), KeyValueSet.class)); return jsonObj; }
public boolean equals(Object object) { if(object instanceof TableMeta) { TableMeta other = (TableMeta) object; boolean eq = this.getDataFormat().equals(other.getDataFormat()); eq = eq && this.getOptions().equals(other.getOptions()); return eq; } return false; }
private static void buildWithClause(final StringBuilder sb, TableMeta meta) { KeyValueSet options = meta.getOptions(); if (options != null && options.size() > 0) { sb.append(" WITH ("); // sort table properties in an lexicographic order of the property keys. Map.Entry<String, String>[] entries = meta.getOptions().getAllKeyValus().entrySet().toArray( new Map.Entry[meta.getOptions().size()]); Arrays.sort(entries, new Comparator<Map.Entry<String, String>>() { @Override public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) { return o1.getKey().compareTo(o2.getKey()); } }); // Join all properties by comma (',') sb.append(StringUtils.join(entries, ", ", new Function<Map.Entry<String, String>, String>() { @Override public String apply(Map.Entry<String, String> e) { return "'" + e.getKey() + "'='" + e.getValue() + "'"; } })); sb.append(")"); } }
@Override public FormatProperty getFormatProperty(TableMeta meta) { KeyValueSet tableProperty = meta.getOptions(); if (tableProperty.isTrue(HBaseStorageConstants.INSERT_PUT_MODE) || tableProperty.isTrue(StorageConstants.INSERT_DIRECTLY)) { return PUT_MODE_PROPERTIES; } else { return HFILE_FORMAT_PROPERTIES; } }
public URI prepareStagingSpace(TajoConf conf, String queryId, OverridableConf context, TableMeta meta) throws IOException { if (!meta.getOptions().isTrue(HBaseStorageConstants.INSERT_PUT_MODE)) { return TablespaceManager.getDefault().prepareStagingSpace(conf, queryId, context, meta); } else { throw new IOException("Staging phase is not supported in this storage."); } }
@Override public URI getStagingUri(OverridableConf context, String queryId, TableMeta meta) throws IOException { if (meta.getOptions().isTrue(HBaseStorageConstants.INSERT_PUT_MODE)) { throw new IOException("Staging phase is not supported in this storage."); } else { return TablespaceManager.getDefault().getStagingUri(context, queryId, meta); } }
/** * Creates HTableDescription using table meta data. * * @param tableMeta * @param schema * @return * @throws java.io.IOException */ public static HTableDescriptor parseHTableDescriptor(TableMeta tableMeta, Schema schema) throws MissingTablePropertyException, InvalidTablePropertyException { String hbaseTableName = tableMeta.getOption(HBaseStorageConstants.META_TABLE_KEY, ""); if (hbaseTableName == null || hbaseTableName.trim().isEmpty()) { throw new MissingTablePropertyException(HBaseStorageConstants.META_TABLE_KEY, hbaseTableName); } TableName hTableName = TableName.valueOf(hbaseTableName); ColumnMapping columnMapping = new ColumnMapping(schema, tableMeta.getOptions()); HTableDescriptor hTableDescriptor = new HTableDescriptor(hTableName); Collection<String> columnFamilies = columnMapping.getColumnFamilyNames(); //If 'columns' attribute is empty, Tajo table columns are mapped to all HBase table column. if (columnFamilies.isEmpty()) { for (Column eachColumn: schema.getRootColumns()) { columnFamilies.add(eachColumn.getSimpleName()); } } for (String eachColumnFamily: columnFamilies) { hTableDescriptor.addFamily(new HColumnDescriptor(eachColumnFamily)); } return hTableDescriptor; }
columnMapping = new ColumnMapping(schema, meta.getOptions()); } catch (TajoException e) { throw new TajoInternalError(e);
private List<HBaseFragment> getRawSplits(String inputSourceId, TableDesc table, @Nullable EvalNode filterCondition) throws IOException, TajoException { final ColumnMapping columnMapping = new ColumnMapping(table.getSchema(), table.getMeta().getOptions()); try (final HTable htable = new HTable(hbaseConf, table.getMeta().getOption(HBaseStorageConstants.META_TABLE_KEY))) { final RegionSizeCalculator sizeCalculator = new RegionSizeCalculator(htable); final org.apache.hadoop.hbase.util.Pair<byte[][], byte[][]> tableRange = htable.getStartEndKeys(); if (isEmptyRegion(tableRange)) { return createEmptyFragment(table, inputSourceId, htable, sizeCalculator); } final Pair<List<byte []>, List<byte []>> selectedRange = getSelectedKeyRange( columnMapping, getIndexPredications(columnMapping, table, filterCondition)); // region startkey -> HBaseFragment List<HBaseFragment> fragments = new ArrayList<>(convertRangeToFragment(table, inputSourceId, htable, sizeCalculator, tableRange, selectedRange)); Collections.sort(fragments); if (!fragments.isEmpty()) { fragments.get(fragments.size() - 1).setLast(true); } return ImmutableList.copyOf(fragments); } }
ColumnMapping columnMapping = new ColumnMapping(schema, meta.getOptions()); boolean[] isBinaryColumns = columnMapping.getIsBinaryColumns(); boolean[] isRowKeys = columnMapping.getIsRowKeyMappings();
ColumnMapping columnMapping = new ColumnMapping(tableDesc.getSchema(), tableDesc.getMeta().getOptions());
/** * Returns columns which are mapped to the rowkey of the hbase table. * * @param tableDesc * @return * @throws java.io.IOException */ private Column[] getIndexableColumns(TableDesc tableDesc) throws MissingTablePropertyException, InvalidTablePropertyException { ColumnMapping columnMapping = new ColumnMapping(tableDesc.getSchema(), tableDesc.getMeta().getOptions()); boolean[] isRowKeyMappings = columnMapping.getIsRowKeyMappings(); int[] rowKeyIndexes = columnMapping.getRowKeyFieldIndexes(); Column indexColumn = null; for (int i = 0; i < isRowKeyMappings.length; i++) { if (isRowKeyMappings[i]) { if (columnMapping.getNumRowKeys() == 1 || rowKeyIndexes[i] == 0) { indexColumn = tableDesc.getSchema().getColumn(i); } } } return new Column[]{indexColumn}; }
ColumnMapping columnMapping = new ColumnMapping(schema, tableMeta.getOptions()); int numRowKeys = 0; boolean[] isRowKeyMappings = columnMapping.getIsRowKeyMappings();
public void setTargetTable(TableDesc desc) { setTableName(desc.getName()); if (desc.hasPartition()) { tableSchema = desc.getLogicalSchema(); } else { tableSchema = desc.getSchema(); } if (desc.getUri() != null) { setUri(desc.getUri()); } setOptions(desc.getMeta().getOptions()); setDataFormat(desc.getMeta().getDataFormat()); if (desc.hasPartition()) { this.setPartitionMethod(desc.getPartitionMethod()); } }
columnMapping = new ColumnMapping(schema, meta.getOptions()); } catch (TajoException e) { new TajoInternalError(e);
public LogicalNode handleCreateTableLike(PlanContext context, CreateTable expr, CreateTableNode createTableNode) throws TajoException { String parentTableName = expr.getLikeParentTableName(); if (CatalogUtil.isFQTableName(parentTableName) == false) { parentTableName = CatalogUtil.buildFQName(context.queryContext.get(SessionVars.CURRENT_DATABASE), parentTableName); } TableDesc baseTable = catalog.getTableDesc(parentTableName); if(baseTable == null) { throw new UndefinedTableException(parentTableName); } PartitionMethodDesc partitionDesc = baseTable.getPartitionMethod(); createTableNode.setTableSchema(baseTable.getSchema()); createTableNode.setPartitionMethod(partitionDesc); createTableNode.setDataFormat(CatalogUtil.getBackwardCompitableDataFormat(baseTable.getMeta().getDataFormat())); createTableNode.setOptions(baseTable.getMeta().getOptions()); createTableNode.setExternal(baseTable.isExternal()); if(baseTable.isExternal()) { createTableNode.setUri(baseTable.getUri()); } return createTableNode; }
public void execSimpleQuery(QueryContext queryContext, Session session, String query, LogicalPlan plan, SubmitQueryResponse.Builder response) throws Exception { ScanNode scanNode = plan.getRootBlock().getNode(NodeType.SCAN); final TableDesc table = scanNode.getTableDesc(); if (table.hasPartition()) { scanNode = plan.getRootBlock().getNode(NodeType.PARTITIONS_SCAN); } final TableDesc resultDesc = new TableDesc("", scanNode.getOutSchema(), new TableMeta(BuiltinStorages.DRAW, table.getMeta().getOptions()), null); // push down limit int maxRow = Integer.MAX_VALUE; if (plan.getRootBlock().hasNode(NodeType.LIMIT)) { LimitNode limitNode = plan.getRootBlock().getNode(NodeType.LIMIT); maxRow = (int) limitNode.getFetchFirstNum(); scanNode.setLimit(maxRow); } final QueryInfo queryInfo = context.getQueryJobManager().createNewSimpleQuery(queryContext, session, query, (LogicalRootNode) plan.getRootBlock().getRoot()); final NonForwardQueryResultScanner queryResultScanner = new NonForwardQueryResultFileScanner( context.getConf(), session.getSessionId(), queryInfo.getQueryId(), scanNode, maxRow); queryResultScanner.init(); session.addNonForwardQueryResultScanner(queryResultScanner); response.setState(OK); response.setQueryId(queryInfo.getQueryId().getProto()); response.setResultType(ResultType.ENCLOSED); response.setMaxRowNum(maxRow); response.setTableDesc(resultDesc.getProto()); }