Search in sources :

Example 96 with Format

use of java.text.Format in project phoenix by apache.

the class ExplainTable method appendPKColumnValue.

private void appendPKColumnValue(StringBuilder buf, byte[] range, Boolean isNull, int slotIndex, boolean changeViewIndexId) {
    if (Boolean.TRUE.equals(isNull)) {
        buf.append("null");
        return;
    }
    if (Boolean.FALSE.equals(isNull)) {
        buf.append("not null");
        return;
    }
    if (range.length == 0) {
        buf.append('*');
        return;
    }
    ScanRanges scanRanges = context.getScanRanges();
    PDataType type = scanRanges.getSchema().getField(slotIndex).getDataType();
    SortOrder sortOrder = tableRef.getTable().getPKColumns().get(slotIndex).getSortOrder();
    if (sortOrder == SortOrder.DESC) {
        buf.append('~');
        ImmutableBytesWritable ptr = new ImmutableBytesWritable(range);
        type.coerceBytes(ptr, type, sortOrder, SortOrder.getDefault());
        range = ptr.get();
    }
    if (changeViewIndexId) {
        Short s = (Short) type.toObject(range);
        s = (short) (s + (-Short.MAX_VALUE));
        buf.append(s.toString());
    } else {
        Format formatter = context.getConnection().getFormatter(type);
        buf.append(type.toStringLiteral(range, formatter));
    }
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) Format(java.text.Format) PDataType(org.apache.phoenix.schema.types.PDataType) SortOrder(org.apache.phoenix.schema.SortOrder) ScanRanges(org.apache.phoenix.compile.ScanRanges)

Example 97 with Format

use of java.text.Format in project phoenix by apache.

the class ToNumberParseNode method create.

@Override
public FunctionExpression create(List<Expression> children, StatementContext context) throws SQLException {
    PDataType dataType = children.get(0).getDataType();
    // either date or number format string
    String formatString = (String) ((LiteralExpression) children.get(1)).getValue();
    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);
}
Also used : Format(java.text.Format) PDataType(org.apache.phoenix.schema.types.PDataType) SQLException(java.sql.SQLException) FunctionArgumentType(org.apache.phoenix.expression.function.FunctionArgumentType) ToNumberFunction(org.apache.phoenix.expression.function.ToNumberFunction)

Example 98 with Format

use of java.text.Format in project phoenix by apache.

the class UpgradeUtil method getSysCatalogSnapshotName.

public static final String getSysCatalogSnapshotName(long currentSystemTableTimestamp) {
    String tableString = SYSTEM_CATALOG_NAME;
    Format formatter = new SimpleDateFormat("yyyyMMddHHmmss");
    String date = formatter.format(new Date(System.currentTimeMillis()));
    String upgradingFrom = getVersion(currentSystemTableTimestamp);
    return "SNAPSHOT_" + tableString + "_" + upgradingFrom + "_TO_" + CURRENT_CLIENT_VERSION + "_" + date;
}
Also used : Format(java.text.Format) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.sql.Date)

Example 99 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_String_parseErrorLongText.

@Test(expectedExceptions = ParseException.class)
public void test_toFormat_parseObject_String_parseErrorLongText() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    try {
        format.parseObject("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
        assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
        assertEquals(ex.getErrorIndex(), 3);
        throw ex;
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) Format(java.text.Format) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 100 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_StringParsePosition_dateTimeError.

@Test(expectedExceptions = ParseException.class)
public void test_toFormat_parseObject_StringParsePosition_dateTimeError() throws Exception {
    Format format = DATE_FORMATTER.toFormat(LocalDate::from);
    format.parseObject("ONE2012 07 32");
}
Also used : Format(java.text.Format) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

Format (java.text.Format)160 SimpleDateFormat (java.text.SimpleDateFormat)63 DecimalFormat (java.text.DecimalFormat)39 Test (org.junit.Test)38 DateFormat (java.text.DateFormat)34 Date (java.util.Date)32 NumberFormat (java.text.NumberFormat)29 DateTimeFormatter (java.time.format.DateTimeFormatter)27 ChoiceFormat (java.text.ChoiceFormat)24 ParsePosition (java.text.ParsePosition)22 MessageFormat (java.text.MessageFormat)20 FieldPosition (java.text.FieldPosition)16 Test (org.testng.annotations.Test)16 IOException (java.io.IOException)15 ParseException (java.text.ParseException)11 ArrayList (java.util.ArrayList)11 Locale (java.util.Locale)10 AttributedString (java.text.AttributedString)9 TemporalAccessor (java.time.temporal.TemporalAccessor)7 Calendar (java.util.Calendar)7