Java Code Examples for org.apache.phoenix.compile.StatementContext#getDateFormatter()

The following examples show how to use org.apache.phoenix.compile.StatementContext#getDateFormatter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToCharParseNode.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public FunctionExpression create(List<Expression> children, StatementContext context) throws SQLException {
    PDataType dataType = children.get(0).getDataType();
    String formatString = (String)((LiteralExpression)children.get(1)).getValue(); // either date or number format string
    Format formatter;
    FunctionArgumentType type;
    if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
        if (formatString == null) {
            formatString = context.getDateFormat();
            formatter = context.getDateFormatter();
        } else {
            formatter = FunctionArgumentType.TEMPORAL.getFormatter(formatString);
        }
        type = FunctionArgumentType.TEMPORAL;
    }
    else if (dataType.isCoercibleTo(PDecimal.INSTANCE)) {
        if (formatString == null)
            formatString = context.getNumberFormat();
        formatter = FunctionArgumentType.NUMERIC.getFormatter(formatString);
        type = FunctionArgumentType.NUMERIC;
    }
    else {
        throw new SQLException(dataType + " type is unsupported for TO_CHAR().  Numeric and temporal types are supported.");
    }
    return new ToCharFunction(children, type, formatString, formatter);
}
 
Example 2
Source File: ToCharParseNode.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public FunctionExpression create(List<Expression> children, StatementContext context) throws SQLException {
    PDataType dataType = children.get(0).getDataType();
    String formatString = (String)((LiteralExpression)children.get(1)).getValue(); // either date or number format string
    Format formatter;
    FunctionArgumentType type;
    if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
        if (formatString == null) {
            formatString = context.getDateFormat();
            formatter = context.getDateFormatter();
        } else {
            formatter = FunctionArgumentType.TEMPORAL.getFormatter(formatString);
        }
        type = FunctionArgumentType.TEMPORAL;
    }
    else if (dataType.isCoercibleTo(PDecimal.INSTANCE)) {
        if (formatString == null)
            formatString = context.getNumberFormat();
        formatter = FunctionArgumentType.NUMERIC.getFormatter(formatString);
        type = FunctionArgumentType.NUMERIC;
    }
    else {
        throw new SQLException(dataType + " type is unsupported for TO_CHAR().  Numeric and temporal types are supported.");
    }
    return new ToCharFunction(children, type, formatString, formatter);
}
 
Example 3
Source File: ToNumberParseNode.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public FunctionExpression create(List<Expression> children, StatementContext context) throws SQLException {
    PDataType dataType = children.get(0).getDataType();
    String formatString = (String)((LiteralExpression)children.get(1)).getValue(); // either date or number format string
    Format formatter =  null;
    FunctionArgumentType type;
    
    if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
        if (formatString == null) {
            formatString = context.getDateFormat();
            formatter = context.getDateFormatter();
        } else {
            formatter = FunctionArgumentType.TEMPORAL.getFormatter(formatString);
        }
        type = FunctionArgumentType.TEMPORAL;
    }
    else if (dataType.isCoercibleTo(PChar.INSTANCE)) {
        if (formatString != null) {
            formatter = FunctionArgumentType.CHAR.getFormatter(formatString);
        }
        type = FunctionArgumentType.CHAR;
    }
    else {
        throw new SQLException(dataType + " type is unsupported for TO_NUMBER().  Numeric and temporal types are supported.");
    }
    return new ToNumberFunction(children, type, formatString, formatter);
}
 
Example 4
Source File: ToNumberParseNode.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public FunctionExpression create(List<Expression> children, StatementContext context) throws SQLException {
    PDataType dataType = children.get(0).getDataType();
    String formatString = (String)((LiteralExpression)children.get(1)).getValue(); // either date or number format string
    Format formatter =  null;
    FunctionArgumentType type;
    
    if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
        if (formatString == null) {
            formatString = context.getDateFormat();
            formatter = context.getDateFormatter();
        } else {
            formatter = FunctionArgumentType.TEMPORAL.getFormatter(formatString);
        }
        type = FunctionArgumentType.TEMPORAL;
    }
    else if (dataType.isCoercibleTo(PChar.INSTANCE)) {
        if (formatString != null) {
            formatter = FunctionArgumentType.CHAR.getFormatter(formatString);
        }
        type = FunctionArgumentType.CHAR;
    }
    else {
        throw new SQLException(dataType + " type is unsupported for TO_NUMBER().  Numeric and temporal types are supported.");
    }
    return new ToNumberFunction(children, type, formatString, formatter);
}
 
Example 5
Source File: ToNumberFunction.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public ToNumberFunction(List<Expression> children, StatementContext context) throws SQLException {
    super(children.subList(0, 1));
    PDataType dataType = children.get(0).getDataType();
    String formatString = (String)((LiteralExpression)children.get(1)).getValue(); // either date or number format string
    Format formatter =  null;
    FunctionArgumentType type;

    if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
        if (formatString == null) {
            formatString = context.getDateFormat();
            formatter = context.getDateFormatter();
        } else {
            formatter = FunctionArgumentType.TEMPORAL.getFormatter(formatString);
        }
        type = FunctionArgumentType.TEMPORAL;
    }
    else if (dataType.isCoercibleTo(PChar.INSTANCE)) {
        if (formatString != null) {
            formatter = FunctionArgumentType.CHAR.getFormatter(formatString);
        }
        type = FunctionArgumentType.CHAR;
    }
    else {
        throw new SQLException(dataType + " type is unsupported for TO_NUMBER().  Numeric and temporal types are supported.");
    }
    Preconditions.checkNotNull(type);
    this.type = type;
    this.formatString = formatString;
    this.format = formatter;
}
 
Example 6
Source File: ToCharFunction.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public ToCharFunction(List<Expression> children, StatementContext context) throws SQLException {
    super(children.subList(0, 1));
    PDataType dataType = children.get(0).getDataType();
    String formatString = (String)((LiteralExpression)children.get(1)).getValue(); // either date or number format string
    Format formatter;
    FunctionArgumentType type;
    if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
        if (formatString == null) {
            formatString = context.getDateFormat();
            formatter = context.getDateFormatter();
        } else {
            formatter = FunctionArgumentType.TEMPORAL.getFormatter(formatString);
        }
        type = FunctionArgumentType.TEMPORAL;
    }
    else if (dataType.isCoercibleTo(PDecimal.INSTANCE)) {
        if (formatString == null)
            formatString = context.getNumberFormat();
        formatter = FunctionArgumentType.NUMERIC.getFormatter(formatString);
        type = FunctionArgumentType.NUMERIC;
    }
    else {
        throw new SQLException(dataType + " type is unsupported for TO_CHAR().  Numeric and temporal types are supported.");
    }
    Preconditions.checkNotNull(formatString);
    Preconditions.checkNotNull(formatter);
    Preconditions.checkNotNull(type);
    this.type = type;
    this.formatString = formatString;
    this.formatter = formatter;
}