use of io.prestosql.sql.tree.QualifiedName in project hetu-core by openlookeng.
the class DropCubeTask method execute.
@Override
public ListenableFuture<?> execute(DropCube statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
Optional<CubeMetaStore> optionalCubeMetaStore = this.cubeManager.getMetaStore(STAR_TREE);
if (!optionalCubeMetaStore.isPresent()) {
throw new RuntimeException("HetuMetastore is not initialized");
}
CubeMetaStore cubeMetaStore = optionalCubeMetaStore.get();
QualifiedObjectName fullObjectName = createQualifiedObjectName(session, statement, statement.getCubeName());
QualifiedName cubeTableName = QualifiedName.of(fullObjectName.getCatalogName(), fullObjectName.getSchemaName(), fullObjectName.getObjectName());
try {
Optional<CubeMetadata> matchedCube = cubeMetaStore.getMetadataFromCubeName(cubeTableName.toString());
if (!matchedCube.isPresent()) {
if (!statement.isExists()) {
throw new SemanticException(MISSING_CUBE, statement, "Cube '%s' does not exist", cubeTableName);
}
return immediateFuture(null);
}
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, fullObjectName);
tableHandle.ifPresent(handle -> {
accessControl.checkCanDropTable(session.getRequiredTransactionId(), session.getIdentity(), fullObjectName);
metadata.dropTable(session, handle);
});
cubeMetaStore.removeCube(matchedCube.get());
return immediateFuture(null);
} catch (TableNotFoundException s) {
throw new SemanticException(MISSING_CUBE, statement, "Cube '%s' is not Found", cubeTableName.toString());
}
}
use of io.prestosql.sql.tree.QualifiedName in project hetu-core by openlookeng.
the class DropCacheTask method execute.
@Override
public ListenableFuture<?> execute(DropCache statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
if (!PropertyService.getBooleanProperty(HetuConstant.SPLIT_CACHE_MAP_ENABLED)) {
throw new PrestoException(GENERIC_USER_ERROR, "Cache table feature is not enabled");
}
Session session = stateMachine.getSession();
QualifiedObjectName fullObjectName = createQualifiedObjectName(session, statement, statement.getTableName());
QualifiedName tableName = QualifiedName.of(fullObjectName.getCatalogName(), fullObjectName.getSchemaName(), fullObjectName.getObjectName());
SplitCacheMap splitCacheMap = SplitCacheMap.getInstance();
// Check if split cache has predicates for the requested table
if (!splitCacheMap.cacheExists(tableName)) {
throw new SemanticException(MISSING_CACHE, statement, "Cache for table '%s' does not exist", tableName.toString());
}
splitCacheMap.dropCache(tableName, statement.getWhere().map(Expression::toString));
return immediateFuture(null);
}
use of io.prestosql.sql.tree.QualifiedName in project hetu-core by openlookeng.
the class HiveAstBuilder method visitDescribeTable.
@Override
public Node visitDescribeTable(HiveSqlParser.DescribeTableContext context) {
if (context.EXTENDED() != null) {
addDiff(DiffType.UNSUPPORTED, context.EXTENDED().getText(), "[EXTENDED] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported attribute: EXTENDED", context);
}
if (context.FORMATTED() != null) {
addDiff(DiffType.UNSUPPORTED, context.FORMATTED().getText(), "[FORMATTED] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported attribute: FORMATTED", context);
}
if (context.describeTableOption() != null) {
addDiff(DiffType.UNSUPPORTED, context.describeTableOption().getText(), "[DESCRIBE TABLE OPTION] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported Describe statement", context.describeTableOption());
}
String source = context.DESCRIBE() != null ? context.DESCRIBE().getText() : context.DESC().getText();
addDiff(DiffType.MODIFIED, source, "SHOW COLUMNS FROM", format("keyword: [%s] is updated to [SHOW COLUMNS FROM]", source.toUpperCase(ENGLISH)));
QualifiedName qualifiedName = QualifiedName.of(visit(context.describeName().identifier(), Identifier.class));
return new ShowColumns(getLocation(context), qualifiedName);
}
use of io.prestosql.sql.tree.QualifiedName in project hetu-core by openlookeng.
the class HiveAstBuilder method visitFunctionCall.
@Override
public Node visitFunctionCall(HiveSqlParser.FunctionCallContext context) {
Optional<Expression> filter = Optional.empty();
Optional<OrderBy> orderBy = Optional.empty();
Optional<Window> window = visitIfPresent(context.over(), Window.class);
boolean distinct = isDistinct(context.setQuantifier());
QualifiedName name = getQualifiedName(context.qualifiedName());
if (name.toString().equalsIgnoreCase("if")) {
check(context.expression().size() == 3, "Illegal arguments for 'if' function", context);
check(!window.isPresent(), "OVER not valid for 'if' function", context);
check(!distinct, "DISTINCT not valid for 'if' function", context);
Expression elseExpression = (Expression) visit(context.expression(2));
return new IfExpression(getLocation(context), (Expression) visit(context.expression(0)), (Expression) visit(context.expression(1)), elseExpression);
}
if (name.toString().equalsIgnoreCase("nullif")) {
check(context.expression().size() == 2, "Illegal arguments for 'nullif' function", context);
check(!window.isPresent(), "OVER not valid for 'nullif' function", context);
check(!distinct, "DISTINCT not valid for 'nullif' function", context);
return new NullIfExpression(getLocation(context), (Expression) visit(context.expression(0)), (Expression) visit(context.expression(1)));
}
if (name.toString().equalsIgnoreCase("coalesce")) {
check(context.expression().size() > 0, "The 'coalesce' function must have at least one argument", context);
check(!window.isPresent(), "OVER not valid for 'coalesce' function", context);
check(!distinct, "DISTINCT not valid for 'coalesce' function", context);
return new CoalesceExpression(getLocation(context), visit(context.expression(), Expression.class));
}
return new FunctionCall(Optional.of(getLocation(context)), getQualifiedName(context.qualifiedName()), window, filter, orderBy, distinct, false, visit(context.expression(), Expression.class));
}
use of io.prestosql.sql.tree.QualifiedName in project hetu-core by openlookeng.
the class CubeConsole method processComparisonExpression.
/**
* Process the Create Cube Query with Comparison Expression in where clause.
*
* @param createCube createCube
* @param queryRunner queryRunner
* @param outputFormat outputFormat
* @param schemaChanged schemaChanged
* @param usePager usePager
* @param showProgress showProgress
* @param terminal terminal
* @param out out
* @param errorChannel errorChannel
* @param parser parser
* @return boolean
*/
private boolean processComparisonExpression(CreateCube createCube, QueryRunner queryRunner, ClientOptions.OutputFormat outputFormat, Runnable schemaChanged, boolean usePager, boolean showProgress, Terminal terminal, PrintStream out, PrintStream errorChannel, SqlParser parser) {
String whereClause = createCube.getWhere().get().toString();
QualifiedName sourceTableName = createCube.getSourceTableName();
QualifiedName cubeName = createCube.getCubeName();
ComparisonExpression comparisonExpression = (ComparisonExpression) (createCube.getWhere().get());
ComparisonExpression.Operator operator = comparisonExpression.getOperator();
Expression left = comparisonExpression.getLeft();
Expression right = comparisonExpression.getRight();
boolean notEqualOperator = false;
if (operator.getValue().equalsIgnoreCase(NOT_EQUAL_OPERATOR)) {
notEqualOperator = true;
}
if (!(left instanceof SymbolReference) && right instanceof SymbolReference) {
comparisonExpression = new ComparisonExpression(operator.flip(), right, left);
}
if (left instanceof Literal && !(right instanceof Literal)) {
comparisonExpression = new ComparisonExpression(operator.flip(), right, left);
}
Expression columnName = comparisonExpression.getLeft();
// Run Query
String rowCountsDistinctValuesQuery = String.format(SELECT_COLUMN_ROW_COUNT_FROM_STRING, columnName, sourceTableName.toString(), whereClause, columnName, columnName);
if (!processCubeInitialQuery(queryRunner, rowCountsDistinctValuesQuery, outputFormat, schemaChanged, usePager, showProgress, terminal, out, errorChannel)) {
return false;
}
List<List<?>> bufferIterationItems = getListRowBufferIterationItems();
if (bufferIterationItems != null && bufferIterationItems.size() != EMPTY_ROW_BUFFER_ITERATION_ITEMS) {
// this loop process the multiple insert query statements
int end = bufferIterationItems.size() - 1;
for (int i = 0; i <= end; i++) {
List<?> rowBufferItems = bufferIterationItems.get(i);
Expression finalPredicate;
Expression userBoundaryPredicate = null;
String queryInsert;
String minItem = rowBufferItems.get(INDEX_AT_MIN_POSITION).toString();
String maxItem = rowBufferItems.get(INDEX_AT_MAX_POSITION).toString();
switch(cubeColumnDataType) {
case DATATYPE_DOUBLE:
{
finalPredicate = new BetweenPredicate(columnName, parser.createExpression(DATATYPE_DOUBLE + " " + QUOTE_STRING + minItem + QUOTE_STRING, new ParsingOptions()), parser.createExpression(DATATYPE_DOUBLE + " " + QUOTE_STRING + maxItem + QUOTE_STRING, new ParsingOptions()));
userBoundaryPredicate = new ComparisonExpression(operator, left, right);
break;
}
case DATATYPE_REAL:
{
finalPredicate = new BetweenPredicate(columnName, parser.createExpression(DATATYPE_REAL_QUOTE + minItem + QUOTE_STRING, new ParsingOptions()), parser.createExpression(DATATYPE_REAL_QUOTE + maxItem + QUOTE_STRING, new ParsingOptions()));
userBoundaryPredicate = new ComparisonExpression(operator, left, right);
break;
}
case DATATYPE_DECIMAL:
{
finalPredicate = new BetweenPredicate(columnName, parser.createExpression(DATATYPE_DECIMAL + " " + QUOTE_STRING + minItem + QUOTE_STRING, new ParsingOptions()), parser.createExpression(DATATYPE_DECIMAL + " " + QUOTE_STRING + maxItem + QUOTE_STRING, new ParsingOptions()));
userBoundaryPredicate = new ComparisonExpression(operator, left, right);
break;
}
case DATATYPE_DATE:
{
finalPredicate = new BetweenPredicate(left, parser.createExpression(DATATYPE_DATE_QUOTE + minItem + QUOTE_STRING, new ParsingOptions()), parser.createExpression(DATATYPE_DATE_QUOTE + maxItem + QUOTE_STRING, new ParsingOptions()));
userBoundaryPredicate = new ComparisonExpression(operator, left, right);
break;
}
case DATATYPE_TIMESTAMP:
{
finalPredicate = new BetweenPredicate(left, parser.createExpression(DATATYPE_TIMESTAMP_QUOTE + minItem + QUOTE_STRING, new ParsingOptions()), parser.createExpression(DATATYPE_TIMESTAMP_QUOTE + maxItem + QUOTE_STRING, new ParsingOptions()));
userBoundaryPredicate = new ComparisonExpression(operator, left, right);
break;
}
case DATATYPE_TINYINT:
{
finalPredicate = new BetweenPredicate(left, parser.createExpression(DATATYPE_TINYINT_QUOTE + minItem + QUOTE_STRING, new ParsingOptions()), parser.createExpression(DATATYPE_TINYINT_QUOTE + maxItem + QUOTE_STRING, new ParsingOptions()));
userBoundaryPredicate = new ComparisonExpression(operator, left, right);
break;
}
case DATATYPE_BIGINT:
{
finalPredicate = new BetweenPredicate(left, parser.createExpression(DATATYPE_BIGINT_QUOTE + minItem + QUOTE_STRING, new ParsingOptions()), parser.createExpression(DATATYPE_BIGINT_QUOTE + maxItem + QUOTE_STRING, new ParsingOptions()));
userBoundaryPredicate = new ComparisonExpression(operator, left, right);
break;
}
case DATATYPE_SMALLINT:
{
finalPredicate = new BetweenPredicate(left, parser.createExpression(DATATYPE_SMALLINT_QUOTE + minItem + QUOTE_STRING, new ParsingOptions()), parser.createExpression(DATATYPE_SMALLINT_QUOTE + maxItem + QUOTE_STRING, new ParsingOptions()));
userBoundaryPredicate = new ComparisonExpression(operator, left, right);
break;
}
case DATATYPE_VARCHAR:
{
finalPredicate = new BetweenPredicate(left, parser.createExpression(QUOTE_STRING + minItem + QUOTE_STRING, new ParsingOptions()), parser.createExpression(QUOTE_STRING + maxItem + QUOTE_STRING, new ParsingOptions()));
userBoundaryPredicate = new ComparisonExpression(operator, left, right);
break;
}
default:
{
finalPredicate = new BetweenPredicate(left, parser.createExpression(minItem, new ParsingOptions()), parser.createExpression(maxItem, new ParsingOptions()));
userBoundaryPredicate = new ComparisonExpression(operator, left, right);
break;
}
}
if (notEqualOperator) {
finalPredicate = new ComparisonExpression(ComparisonExpression.Operator.NOT_EQUAL, left, right);
queryInsert = String.format(INSERT_INTO_CUBE_STRING, cubeName, finalPredicate);
} else if (i == end && userBoundaryPredicate != null) {
queryInsert = String.format(INSERT_INTO_CUBE_STRING, cubeName, userBoundaryPredicate);
} else {
queryInsert = String.format(INSERT_INTO_CUBE_STRING, cubeName, finalPredicate);
}
if (!console.runQuery(queryRunner, queryInsert, outputFormat, schemaChanged, usePager, showProgress, terminal, out, errorChannel)) {
return false;
}
}
} else {
// if the range is within the processing size limit then we run a single insert query only
String queryInsert = String.format(INSERT_INTO_CUBE_STRING, cubeName, whereClause);
if (!console.runQuery(queryRunner, queryInsert, outputFormat, schemaChanged, usePager, showProgress, terminal, out, errorChannel)) {
return false;
}
}
return true;
}
Aggregations