public static Boolean currentTokenAsBoolean(JsonParser parser) throws IOException { switch (parser.currentToken()) { case VALUE_NULL: return null; case VALUE_STRING: case FIELD_NAME: return VarcharOperators.castToBoolean(Slices.utf8Slice(parser.getText())); case VALUE_NUMBER_FLOAT: return DoubleOperators.castToBoolean(parser.getDoubleValue()); case VALUE_NUMBER_INT: return BigintOperators.castToBoolean(parser.getLongValue()); case VALUE_TRUE: return true; case VALUE_FALSE: return false; default: throw new JsonCastException(format("Unexpected token when cast to %s: %s", StandardTypes.BOOLEAN, parser.getText())); } }
private static byte toUpperCase(byte b) { return isLowerCase(b) ? ((byte) (b - 32)) : b; }
byte character = toUpperCase(value.getByte(0)); if (character == 'T' || character == '1') { return true; (toUpperCase(value.getByte(0)) == 'T') && (toUpperCase(value.getByte(1)) == 'R') && (toUpperCase(value.getByte(2)) == 'U') && (toUpperCase(value.getByte(3)) == 'E')) { return true; (toUpperCase(value.getByte(0)) == 'F') && (toUpperCase(value.getByte(1)) == 'A') && (toUpperCase(value.getByte(2)) == 'L') && (toUpperCase(value.getByte(3)) == 'S') && (toUpperCase(value.getByte(4)) == 'E')) { return false;
public static Long currentTokenAsBigint(JsonParser parser) throws IOException { switch (parser.currentToken()) { case VALUE_NULL: return null; case VALUE_STRING: case FIELD_NAME: return VarcharOperators.castToBigint(Slices.utf8Slice(parser.getText())); case VALUE_NUMBER_FLOAT: return DoubleOperators.castToLong(parser.getDoubleValue()); case VALUE_NUMBER_INT: return parser.getLongValue(); case VALUE_TRUE: return BooleanOperators.castToBigint(true); case VALUE_FALSE: return BooleanOperators.castToBigint(false); default: throw new JsonCastException(format("Unexpected token when cast to %s: %s", StandardTypes.BIGINT, parser.getText())); } }
public static Double currentTokenAsDouble(JsonParser parser) throws IOException { switch (parser.currentToken()) { case VALUE_NULL: return null; case VALUE_STRING: case FIELD_NAME: return VarcharOperators.castToDouble(Slices.utf8Slice(parser.getText())); case VALUE_NUMBER_FLOAT: return parser.getDoubleValue(); case VALUE_NUMBER_INT: // An alternative is calling getLongValue and then BigintOperators.castToDouble. // It doesn't work as well because it can result in overflow and underflow exceptions for large integral numbers. return parser.getDoubleValue(); case VALUE_TRUE: return BooleanOperators.castToDouble(true); case VALUE_FALSE: return BooleanOperators.castToDouble(false); default: throw new JsonCastException(format("Unexpected token when cast to %s: %s", StandardTypes.DOUBLE, parser.getText())); } }
public static Long currentTokenAsReal(JsonParser parser) throws IOException { switch (parser.currentToken()) { case VALUE_NULL: return null; case VALUE_STRING: case FIELD_NAME: return VarcharOperators.castToFloat(Slices.utf8Slice(parser.getText())); case VALUE_NUMBER_FLOAT: return (long) floatToRawIntBits(parser.getFloatValue()); case VALUE_NUMBER_INT: // An alternative is calling getLongValue and then BigintOperators.castToReal. // It doesn't work as well because it can result in overflow and underflow exceptions for large integral numbers. return (long) floatToRawIntBits(parser.getFloatValue()); case VALUE_TRUE: return BooleanOperators.castToReal(true); case VALUE_FALSE: return BooleanOperators.castToReal(false); default: throw new JsonCastException(format("Unexpected token when cast to %s: %s", StandardTypes.REAL, parser.getText())); } }
public static Long currentTokenAsInteger(JsonParser parser) throws IOException { switch (parser.currentToken()) { case VALUE_NULL: return null; case VALUE_STRING: case FIELD_NAME: return VarcharOperators.castToInteger(Slices.utf8Slice(parser.getText())); case VALUE_NUMBER_FLOAT: return DoubleOperators.castToInteger(parser.getDoubleValue()); case VALUE_NUMBER_INT: return (long) toIntExact(parser.getLongValue()); case VALUE_TRUE: return BooleanOperators.castToInteger(true); case VALUE_FALSE: return BooleanOperators.castToInteger(false); default: throw new JsonCastException(format("Unexpected token when cast to %s: %s", StandardTypes.INTEGER, parser.getText())); } }
public static Long currentTokenAsTinyint(JsonParser parser) throws IOException { switch (parser.currentToken()) { case VALUE_NULL: return null; case VALUE_STRING: case FIELD_NAME: return VarcharOperators.castToTinyint(Slices.utf8Slice(parser.getText())); case VALUE_NUMBER_FLOAT: return DoubleOperators.castToTinyint(parser.getDoubleValue()); case VALUE_NUMBER_INT: return (long) SignedBytes.checkedCast(parser.getLongValue()); case VALUE_TRUE: return BooleanOperators.castToTinyint(true); case VALUE_FALSE: return BooleanOperators.castToTinyint(false); default: throw new JsonCastException(format("Unexpected token when cast to %s: %s", StandardTypes.TINYINT, parser.getText())); } }
public static Long currentTokenAsSmallint(JsonParser parser) throws IOException { switch (parser.currentToken()) { case VALUE_NULL: return null; case VALUE_STRING: case FIELD_NAME: return VarcharOperators.castToSmallint(Slices.utf8Slice(parser.getText())); case VALUE_NUMBER_FLOAT: return DoubleOperators.castToSmallint(parser.getDoubleValue()); case VALUE_NUMBER_INT: return (long) Shorts.checkedCast(parser.getLongValue()); case VALUE_TRUE: return BooleanOperators.castToSmallint(true); case VALUE_FALSE: return BooleanOperators.castToSmallint(false); default: throw new JsonCastException(format("Unexpected token when cast to %s: %s", StandardTypes.SMALLINT, parser.getText())); } }
private static List<Page> createVarcharPages(int positionCount, int groupCount, int channelCount, boolean hashEnabled) { List<Type> types = Collections.nCopies(channelCount, VARCHAR); ImmutableList.Builder<Page> pages = ImmutableList.builder(); if (hashEnabled) { types = ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT))); } PageBuilder pageBuilder = new PageBuilder(types); for (int position = 0; position < positionCount; position++) { int rand = ThreadLocalRandom.current().nextInt(groupCount); Slice value = Slices.wrappedBuffer(ByteBuffer.allocate(4).putInt(rand)); pageBuilder.declarePosition(); for (int channel = 0; channel < channelCount; channel++) { VARCHAR.writeSlice(pageBuilder.getBlockBuilder(channel), value); } if (hashEnabled) { BIGINT.writeLong(pageBuilder.getBlockBuilder(channelCount), VarcharOperators.hashCode(value)); } if (pageBuilder.isFull()) { pages.add(pageBuilder.build()); pageBuilder.reset(); } } pages.add(pageBuilder.build()); return pages.build(); }
break; case VALUE_STRING: result = VarcharOperators.castToBigint(Slices.utf8Slice(parser.getText())); break; case VALUE_NUMBER_FLOAT:
break; case VALUE_STRING: result = VarcharOperators.castToDouble(Slices.utf8Slice(parser.getText())); break; case VALUE_NUMBER_FLOAT:
private static byte toUpperCase(byte b) { return isLowerCase(b) ? ((byte) (b - 32)) : b; }
break; case VALUE_STRING: result = VarcharOperators.castToBoolean(Slices.utf8Slice(parser.getText())); break; case VALUE_NUMBER_FLOAT:
byte character = toUpperCase(value.getByte(0)); if (character == 'T' || character == '1') { return true; (toUpperCase(value.getByte(0)) == 'T') && (toUpperCase(value.getByte(1)) == 'R') && (toUpperCase(value.getByte(2)) == 'U') && (toUpperCase(value.getByte(3)) == 'E')) { return true; (toUpperCase(value.getByte(0)) == 'F') && (toUpperCase(value.getByte(1)) == 'A') && (toUpperCase(value.getByte(2)) == 'L') && (toUpperCase(value.getByte(3)) == 'S') && (toUpperCase(value.getByte(4)) == 'E')) { return false;