Search in sources :

Example 16 with QualifiedName

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());
    }
}
Also used : TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) QualifiedName(io.prestosql.sql.tree.QualifiedName) CubeMetaStore(io.hetu.core.spi.cube.io.CubeMetaStore) TableHandle(io.prestosql.spi.metadata.TableHandle) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(io.prestosql.metadata.MetadataUtil.createQualifiedObjectName) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 17 with QualifiedName

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);
}
Also used : QualifiedName(io.prestosql.sql.tree.QualifiedName) PrestoException(io.prestosql.spi.PrestoException) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(io.prestosql.metadata.MetadataUtil.createQualifiedObjectName) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 18 with QualifiedName

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);
}
Also used : Identifier(io.prestosql.sql.tree.Identifier) QualifiedName(io.prestosql.sql.tree.QualifiedName) ShowColumns(io.prestosql.sql.tree.ShowColumns)

Example 19 with 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));
}
Also used : OrderBy(io.prestosql.sql.tree.OrderBy) Window(io.prestosql.sql.tree.Window) IfExpression(io.prestosql.sql.tree.IfExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) QualifiedName(io.prestosql.sql.tree.QualifiedName) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) FunctionCall(io.prestosql.sql.tree.FunctionCall) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression)

Example 20 with QualifiedName

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;
}
Also used : BetweenPredicate(io.prestosql.sql.tree.BetweenPredicate) ParsingOptions(io.prestosql.sql.parser.ParsingOptions) SymbolReference(io.prestosql.sql.tree.SymbolReference) QualifiedName(io.prestosql.sql.tree.QualifiedName) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) Literal(io.prestosql.sql.tree.Literal) TimestampLiteral(io.prestosql.sql.tree.TimestampLiteral) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) StringLiteral(io.prestosql.sql.tree.StringLiteral) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

QualifiedName (io.prestosql.sql.tree.QualifiedName)30 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)13 Expression (io.prestosql.sql.tree.Expression)11 Test (org.testng.annotations.Test)10 Identifier (io.prestosql.sql.tree.Identifier)9 FunctionCall (io.prestosql.sql.tree.FunctionCall)8 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)8 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)7 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)7 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)7 LongLiteral (io.prestosql.sql.tree.LongLiteral)7 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)7 SubqueryExpression (io.prestosql.sql.tree.SubqueryExpression)7 ArithmeticUnaryExpression (io.prestosql.sql.tree.ArithmeticUnaryExpression)6 IfExpression (io.prestosql.sql.tree.IfExpression)6 InListExpression (io.prestosql.sql.tree.InListExpression)6 NotExpression (io.prestosql.sql.tree.NotExpression)6 NullIfExpression (io.prestosql.sql.tree.NullIfExpression)6 SearchedCaseExpression (io.prestosql.sql.tree.SearchedCaseExpression)6 SimpleCaseExpression (io.prestosql.sql.tree.SimpleCaseExpression)6