Java 类com.facebook.presto.sql.tree.Extract 实例源码

项目:presto    文件:CanonicalizeExpressions.java   
@Override
public Expression rewriteExtract(Extract node, Void context, ExpressionTreeRewriter<Void> treeRewriter)
{
    Expression value = treeRewriter.rewrite(node.getExpression(), context);

    switch (node.getField()) {
        case YEAR:
            return new FunctionCall(new QualifiedName("year"), ImmutableList.of(value));
        case QUARTER:
            return new FunctionCall(new QualifiedName("quarter"), ImmutableList.of(value));
        case MONTH:
            return new FunctionCall(new QualifiedName("month"), ImmutableList.of(value));
        case WEEK:
            return new FunctionCall(new QualifiedName("week"), ImmutableList.of(value));
        case DAY:
        case DAY_OF_MONTH:
            return new FunctionCall(new QualifiedName("day"), ImmutableList.of(value));
        case DAY_OF_WEEK:
        case DOW:
            return new FunctionCall(new QualifiedName("day_of_week"), ImmutableList.of(value));
        case DAY_OF_YEAR:
        case DOY:
            return new FunctionCall(new QualifiedName("day_of_year"), ImmutableList.of(value));
        case YEAR_OF_WEEK:
        case YOW:
            return new FunctionCall(new QualifiedName("year_of_week"), ImmutableList.of(value));
        case HOUR:
            return new FunctionCall(new QualifiedName("hour"), ImmutableList.of(value));
        case MINUTE:
            return new FunctionCall(new QualifiedName("minute"), ImmutableList.of(value));
        case SECOND:
            return new FunctionCall(new QualifiedName("second"), ImmutableList.of(value));
        case TIMEZONE_MINUTE:
            return new FunctionCall(new QualifiedName("timezone_minute"), ImmutableList.of(value));
        case TIMEZONE_HOUR:
            return new FunctionCall(new QualifiedName("timezone_hour"), ImmutableList.of(value));
    }

    throw new UnsupportedOperationException("not yet implemented: " + node.getField());
}
项目:presto    文件:ExpressionAnalyzer.java   
@Override
protected Type visitExtract(Extract node, StackableAstVisitorContext<AnalysisContext> context)
{
    Type type = process(node.getExpression(), context);
    if (!isDateTimeType(type)) {
        throw new SemanticException(TYPE_MISMATCH, node.getExpression(), "Type of argument to extract must be DATE, TIME, TIMESTAMP, or INTERVAL (actual %s)", type);
    }
    Extract.Field field = node.getField();
    if ((field == TIMEZONE_HOUR || field == TIMEZONE_MINUTE) && !(type.equals(TIME_WITH_TIME_ZONE) || type.equals(TIMESTAMP_WITH_TIME_ZONE))) {
        throw new SemanticException(TYPE_MISMATCH, node.getExpression(), "Type of argument to extract time zone field must have a time zone (actual %s)", type);
    }

    expressionTypes.put(node, BIGINT);
    return BIGINT;
}
项目:hue    文件:VeroGenExpFormatter.java   
@Override
protected String visitExtract(Extract node, Void context)
{
    return "EXTRACT(" + node.getField() + " FROM " + process(node.getExpression(), context) + ")";
}
项目:presto-query-formatter    文件:ExpressionFormatter.java   
@Override
protected String visitExtract(Extract node, StackableAstVisitorContext<Integer> indent)
{
    return "EXTRACT(" + node.getField() + " FROM " + process(node.getExpression(), indent) + ")";
}
项目:presto    文件:AggregationAnalyzer.java   
@Override
protected Boolean visitExtract(Extract node, Void context)
{
    return process(node.getExpression(), context);
}
项目:presto    文件:AstBuilder.java   
@Override
public Node visitExtract(SqlBaseParser.ExtractContext context)
{
    return new Extract(getLocation(context), (Expression) visit(context.valueExpression()), Extract.Field.valueOf(context.identifier().getText().toUpperCase()));
}
项目:presto    文件:ExpressionFormatter.java   
@Override
protected String visitExtract(Extract node, Boolean unmangleNames)
{
    return "EXTRACT(" + node.getField() + " FROM " + process(node.getExpression(), unmangleNames) + ")";
}
项目:EchoQuery    文件:ExpressionFormatter.java   
@Override
protected String visitExtract(Extract node, Boolean unmangleNames)
{
    return "EXTRACT(" + node.getField() + " FROM " + process(node.getExpression(), unmangleNames) + ")";
}