public static Schema getQualifiedLogicalSchema(TableDesc tableDesc, String tableName) { Schema logicalSchema = new Schema(tableDesc.getLogicalSchema()); if (tableName != null) { logicalSchema.setQualifier(tableName); } return logicalSchema; }
public static ResultSet createResultSet(TajoClient client, QueryId queryId, ClientProtos.GetQueryResultResponse response, int fetchRows) throws IOException { TableDesc desc = new TableDesc(response.getTableDesc()); return new FetchResultSet(client, desc.getLogicalSchema(), queryId, fetchRows); }
public static ResultSet createResultSet(TajoClient client, QueryId queryId, ClientProtos.GetQueryResultResponse response, int fetchRows) throws IOException { TableDesc desc = new TableDesc(response.getTableDesc()); return new FetchResultSet(client, desc.getLogicalSchema(), queryId, fetchRows); }
public List<IndexPredication> getIndexPredications(ColumnMapping columnMapping, TableDesc tableDesc, @Nullable EvalNode filterCondition) throws IOException, MissingTablePropertyException, InvalidTablePropertyException { final Column[] indexableColumns = getIndexableColumns(tableDesc); if (indexableColumns == null || indexableColumns.length == 0) { return Collections.EMPTY_LIST; } // Currently supports only single index column. return findIndexablePredicateSet(filterCondition, indexableColumns).stream() .map(set -> getIndexablePredicateValue(columnMapping, set)) .filter(value -> value != null) .map(value -> new IndexPredication( indexableColumns[0], tableDesc.getLogicalSchema().getColumnId(indexableColumns[0].getQualifiedName()), value.getFirst(), value.getSecond())) .collect(Collectors.toList()); }
public static Schema getQualifiedLogicalSchema(TableDesc tableDesc, String tableName) { Schema logicalSchema = SchemaBuilder.builder().addAll(tableDesc.getLogicalSchema().getRootColumns()).build(); if (tableName != null) { logicalSchema.setQualifier(tableName); } return logicalSchema; }
@Override public ResultSet getQueryResult(QueryId queryId) throws QueryNotFoundException { if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { return createNullResultSet(queryId); } GetQueryResultResponse response = getResultResponse(queryId); TableDesc tableDesc = new TableDesc(response.getTableDesc()); return new FetchResultSet(this, tableDesc.getLogicalSchema(), queryId, defaultFetchRows); }
@Override public ResultSet getQueryResult(QueryId queryId) throws QueryNotFoundException { if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { return createNullResultSet(queryId); } GetQueryResultResponse response = getResultResponse(queryId); TableDesc tableDesc = new TableDesc(response.getTableDesc()); return new FetchResultSet(this, tableDesc.getLogicalSchema(), queryId, defaultFetchRows); }
private Schema waitOnResult() throws SQLException { try { QueryStatus status = TajoClientUtil.waitCompletion(tajoClient, queryId); if (status.getState() != TajoProtos.QueryState.QUERY_SUCCEEDED) { throw new SQLException(status.getErrorMessage(), SQLExceptionUtil.toSQLState(ResultCode.INTERNAL_ERROR), ResultCode.INTERNAL_ERROR.getNumber()); } ClientProtos.GetQueryResultResponse response = tajoClient.getResultResponse(queryId); TableDesc tableDesc = new TableDesc(response.getTableDesc()); return tableDesc.getLogicalSchema(); } catch (TajoException e) { throw SQLExceptionUtil.toSQLException(e); } } }
private Schema waitOnResult() throws SQLException { try { QueryStatus status = TajoClientUtil.waitCompletion(tajoClient, queryId); if (status.getState() != TajoProtos.QueryState.QUERY_SUCCEEDED) { throw new SQLException(status.getErrorMessage(), SQLExceptionUtil.toSQLState(ResultCode.INTERNAL_ERROR), ResultCode.INTERNAL_ERROR.getNumber()); } ClientProtos.GetQueryResultResponse response = tajoClient.getResultResponse(queryId); TableDesc tableDesc = new TableDesc(response.getTableDesc()); return tableDesc.getLogicalSchema(); } catch (TajoException e) { throw SQLExceptionUtil.toSQLException(e); } } }
public List<IndexPredication> getIndexPredications(ColumnMapping columnMapping, TableDesc tableDesc, @Nullable EvalNode filterCondition) throws IOException, MissingTablePropertyException, InvalidTablePropertyException { List<IndexPredication> indexPredications = new ArrayList<IndexPredication>(); Column[] indexableColumns = getIndexableColumns(tableDesc); if (indexableColumns != null && indexableColumns.length == 1) { // Currently supports only single index column. List<Set<EvalNode>> indexablePredicateList = findIndexablePredicateSet(filterCondition, indexableColumns); for (Set<EvalNode> eachEvalSet: indexablePredicateList) { Pair<Datum, Datum> indexPredicationValues = getIndexablePredicateValue(columnMapping, eachEvalSet); if (indexPredicationValues != null) { IndexPredication indexPredication = new IndexPredication(); indexPredication.setColumn(indexableColumns[0]); indexPredication.setColumnId(tableDesc.getLogicalSchema().getColumnId(indexableColumns[0].getQualifiedName())); indexPredication.setStartValue(indexPredicationValues.getFirst()); indexPredication.setStopValue(indexPredicationValues.getSecond()); indexPredications.add(indexPredication); } } } return indexPredications; }
} else { if (rowBlock == null) { rowBlock = new MemoryRowBlock(SchemaUtil.toDataTypes(tableDesc.getLogicalSchema()));
private void createColumnPartitionedTable() throws Exception { String tableName = IdentifierUtil.normalizeIdentifier("ColumnPartitionedTable"); ResultSet res = executeString( "create table " + tableName + " (col1 int4, col2 int4) partition by column(key float8) "); res.close(); assertTrue(catalog.existsTable(DEFAULT_DATABASE_NAME, tableName)); assertEquals(2, catalog.getTableDesc(DEFAULT_DATABASE_NAME, tableName).getSchema().size()); assertEquals(3, catalog.getTableDesc(DEFAULT_DATABASE_NAME, tableName).getLogicalSchema().size()); res = testBase.execute( "insert overwrite into " + tableName + " select l_orderkey, l_partkey, l_quantity from lineitem"); res.close(); }
public static ResultSet createResultSet(QueryClient client, ClientProtos.SubmitQueryResponse response, int fetchRows) { if (response.hasTableDesc()) { // non-forward query // select * from table1 [limit 10] int fetchRowNum = fetchRows; if (response.hasSessionVars()) { for (PrimitiveProtos.KeyValueProto eachKeyValue: response.getSessionVars().getKeyvalList()) { if (eachKeyValue.getKey().equals(SessionVars.FETCH_ROWNUM.keyname())) { fetchRowNum = Integer.parseInt(eachKeyValue.getValue()); } } } TableDesc tableDesc = new TableDesc(response.getTableDesc()); return new FetchResultSet(client, tableDesc.getLogicalSchema(), new QueryId(response.getQueryId()), fetchRowNum); } else { // simple eval query // select substr('abc', 1, 2) ClientProtos.SerializedResultSet serializedResultSet = response.getResultSet(); return new TajoMemoryResultSet(new QueryId(response.getQueryId()), SchemaFactory.newV1(serializedResultSet.getSchema()), serializedResultSet, client.getClientSideSessionVars()); } }
public static ResultSet createResultSet(QueryClient client, ClientProtos.SubmitQueryResponse response, int fetchRows) { if (response.hasTableDesc()) { // non-forward query // select * from table1 [limit 10] int fetchRowNum = fetchRows; if (response.hasSessionVars()) { for (PrimitiveProtos.KeyValueProto eachKeyValue: response.getSessionVars().getKeyvalList()) { if (eachKeyValue.getKey().equals(SessionVars.FETCH_ROWNUM.keyname())) { fetchRowNum = Integer.parseInt(eachKeyValue.getValue()); } } } TableDesc tableDesc = new TableDesc(response.getTableDesc()); return new FetchResultSet(client, tableDesc.getLogicalSchema(), new QueryId(response.getQueryId()), fetchRowNum); } else { // simple eval query // select substr('abc', 1, 2) ClientProtos.SerializedResultSet serializedResultSet = response.getResultSet(); return new TajoMemoryResultSet(new QueryId(response.getQueryId()), new Schema(serializedResultSet.getSchema()), serializedResultSet, client.getClientSideSessionVars()); } }
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().getPropertySet()); setDataFormat(desc.getMeta().getDataFormat()); if (desc.hasPartition()) { this.setPartitionMethod(desc.getPartitionMethod()); } }
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()); } }
Schema schema = table.getLogicalSchema();
@Test public final void testCreateColumnPartitionedTableWithSelectedColumns() throws Exception { ResultSet res = null; String tableName = IdentifierUtil.normalizeIdentifier("testCreateColumnPartitionedTableWithSelectedColumns"); if (nodeType == NodeType.INSERT) { res = executeString( "create table " + tableName + " (col1 int4, col2 int4, null_col int4) partition by column(key float8) "); res.close(); assertTrue(catalog.existsTable(DEFAULT_DATABASE_NAME, tableName)); assertEquals(3, catalog.getTableDesc(DEFAULT_DATABASE_NAME, tableName).getSchema().size()); assertEquals(4, catalog.getTableDesc(DEFAULT_DATABASE_NAME, tableName).getLogicalSchema().size()); res = executeString("insert overwrite into " + tableName + " (col1, col2, key) select l_orderkey, " + "l_partkey, l_quantity from lineitem"); } else { res = executeString("create table " + tableName + " (col1 int4, col2 int4, null_col int4)" + " partition by column(key float8) AS select l_orderkey, l_partkey, null, l_quantity from lineitem"); } res.close(); TableDesc tableDesc = catalog.getTableDesc(DEFAULT_DATABASE_NAME, tableName); verifyPartitionDirectoryFromCatalog(DEFAULT_DATABASE_NAME, tableName, new String[]{"key"}, tableDesc.getStats().getNumRows()); executeString("DROP TABLE " + tableName + " PURGE").close(); }
assertEquals(3, catalog.getTableDesc(databaseName, tableName).getLogicalSchema().size());
assertEquals(3, catalog.getTableDesc(DEFAULT_DATABASE_NAME, tableName).getLogicalSchema().size());