@Override public String getDisplayName() { return "map(" + keyType.getDisplayName() + ", " + valueType.getDisplayName() + ")"; }
@Override public String getDisplayName() { return ARRAY + "(" + elementType.getDisplayName() + ")"; } }
private void checkFieldTypeOneOf(FieldType declaredFieldType, String columnName, FieldType... allowedFieldTypes) { if (!Arrays.asList(allowedFieldTypes).contains(declaredFieldType)) { throw new IllegalArgumentException(format( "Wrong dataFormat '%s' specified for column '%s'; %s type implies use of %s", declaredFieldType.name(), columnName, columnType.getDisplayName(), Joiner.on("/").join(allowedFieldTypes))); } }
private String formatOutputs(Iterable<Symbol> symbols) { return Joiner.on(", ").join(Iterables.transform(symbols, input -> input + ":" + types.get(input).getDisplayName())); }
private String getVarcharValue(Type type, Object value) { if (type instanceof VarcharType) { return ((Slice) value).toStringUtf8(); } if (type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType || type instanceof BigintType) { return ((Long) value).toString(); } if (type instanceof BooleanType) { return ((Boolean) value).toString(); } throw new PrestoException(NOT_SUPPORTED, format("Unsupported data type in EXPLAIN (TYPE IO): %s", type.getDisplayName())); }
@Override public String getDisplayName() { // Convert to standard sql name StringBuilder result = new StringBuilder(); result.append(ROW).append('('); for (Field field : fields) { String typeDisplayName = field.getType().getDisplayName(); if (field.getName().isPresent()) { result.append(field.getName().get()).append(' ').append(typeDisplayName); } else { result.append(typeDisplayName); } result.append(", "); } result.setLength(result.length() - 2); result.append(')'); return result.toString(); }
private StateField(String name, Class<?> type, Object initialValue, String getterName, Optional<Type> sqlType) { this.name = requireNonNull(name, "name is null"); checkArgument(!name.isEmpty(), "name is empty"); this.type = requireNonNull(type, "type is null"); this.getterName = requireNonNull(getterName, "getterName is null"); this.initialValue = initialValue; checkArgument(sqlType != null, "sqlType is null"); if (sqlType.isPresent()) { checkArgument( (sqlType.get().getJavaType() == type) || ((type == byte.class) && TINYINT.equals(sqlType.get())) || ((type == int.class) && INTEGER.equals(sqlType.get())), "Stack type (%s) and provided sql type (%s) are incompatible", type.getName(), sqlType.get().getDisplayName()); } else { sqlType = sqlTypeFromStackType(type); } this.sqlType = sqlType; }
public static JsonFieldDecoder throwUnsupportedColumnType(DecoderColumnHandle column) { if (column.getDataFormat() == null) { throw new IllegalArgumentException(format("unsupported column type '%s' for column '%s'", column.getType().getDisplayName(), column.getName())); } throw new IllegalArgumentException(format("unsupported column type '%s' for column '%s' with data format '%s'", column.getType(), column.getName(), column.getDataFormat())); } }
private static void assertColumnSpec(ResultSet rs, int jdbcType, Long columnSize, Long numPrecRadix, Long decimalDigits, Long charOctetLength, Type type) throws SQLException { String message = " of " + type.getDisplayName() + ": "; assertTrue(rs.next()); assertEquals(rs.getObject("DATA_TYPE"), (long) jdbcType, "DATA_TYPE" + message); assertEquals(rs.getObject("COLUMN_SIZE"), columnSize, "COLUMN_SIZE" + message); assertEquals(rs.getObject("NUM_PREC_RADIX"), numPrecRadix, "NUM_PREC_RADIX" + message); assertEquals(rs.getObject("DECIMAL_DIGITS"), decimalDigits, "DECIMAL_DIGITS" + message); assertEquals(rs.getObject("CHAR_OCTET_LENGTH"), charOctetLength, "CHAR_OCTET_LENGTH" + message); }
public static Block serializeObject(Type type, BlockBuilder builder, Object object) { if (ROW.equals(type.getTypeSignature().getBase())) { return serializeStruct(type, builder, object); } if (MAP.equals(type.getTypeSignature().getBase()) || ARRAY.equals(type.getTypeSignature().getBase())) { throw new IllegalArgumentException("Type not supported: " + type.getDisplayName()); } return serializePrimitive(type, builder, object); }
private static Class<?> getObjectType(Type type) { if (type.equals(BOOLEAN)) { return boolean.class; } if (type.equals(BIGINT)) { return long.class; } if (type.equals(DOUBLE)) { return double.class; } if (type.equals(VARCHAR)) { return String.class; } if (type.getTypeSignature().getBase().equals(ARRAY)) { getObjectType(type.getTypeParameters().get(0)); return List.class; } if (type.getTypeSignature().getBase().equals(MAP)) { getObjectType(type.getTypeParameters().get(0)); getObjectType(type.getTypeParameters().get(1)); return Map.class; } throw new IllegalArgumentException("Unsupported argument type: " + type.getDisplayName()); } }
public CsvColumnDecoder(DecoderColumnHandle columnHandle) { try { requireNonNull(columnHandle, "columnHandle is null"); checkArgument(!columnHandle.isInternal(), "unexpected internal column '%s'", columnHandle.getName()); columnName = columnHandle.getName(); checkArgument(columnHandle.getFormatHint() == null, "unexpected format hint '%s' defined for column '%s'", columnHandle.getFormatHint(), columnName); checkArgument(columnHandle.getDataFormat() == null, "unexpected data format '%s' defined for column '%s'", columnHandle.getDataFormat(), columnName); columnType = columnHandle.getType(); checkArgument(columnHandle.getMapping() != null, "mapping not defined for column '%s'", columnName); try { columnIndex = Integer.parseInt(columnHandle.getMapping()); } catch (NumberFormatException e) { throw new IllegalArgumentException(format("invalid mapping '%s' for column '%s'", columnHandle.getMapping(), columnName)); } checkArgument(columnIndex >= 0, "invalid mapping '%s' for column '%s'", columnHandle.getMapping(), columnName); checkArgument(isSupportedType(columnType), "Unsupported column type '%s' for column '%s'", columnType.getDisplayName(), columnName); } catch (IllegalArgumentException e) { throw new PrestoException(GENERIC_USER_ERROR, e); } }
public static int getMaxCodePointCount(Type type) { if (isVarcharType(type)) { VarcharType varcharType = (VarcharType) type; return varcharType.isUnbounded() ? -1 : varcharType.getLengthSafe(); } if (isCharType(type)) { return ((CharType) type).getLength(); } if (isVarbinaryType(type)) { return -1; } throw new IllegalArgumentException("Unsupported encoding " + type.getDisplayName()); }
@Test public void testDisplayName() { TypeManager typeManager = new TypeRegistry(); Type function = typeManager.getType(TypeSignature.parseTypeSignature("function<row(field double),bigint>")); assertEquals(function.getDisplayName(), "function<row(field double),bigint>"); } }
private static Row createDescribeOutputRow(Field field, Analysis analysis) { LongLiteral typeSize = new LongLiteral("0"); if (field.getType() instanceof FixedWidthType) { typeSize = new LongLiteral(String.valueOf(((FixedWidthType) field.getType()).getFixedSize())); } String columnName; if (field.getName().isPresent()) { columnName = field.getName().get(); } else { int columnIndex = ImmutableList.copyOf(analysis.getOutputDescriptor().getVisibleFields()).indexOf(field); columnName = "_col" + columnIndex; } Optional<QualifiedObjectName> originTable = field.getOriginTable(); return row( new StringLiteral(columnName), new StringLiteral(originTable.map(QualifiedObjectName::getCatalogName).orElse("")), new StringLiteral(originTable.map(QualifiedObjectName::getSchemaName).orElse("")), new StringLiteral(originTable.map(QualifiedObjectName::getObjectName).orElse("")), new StringLiteral(field.getType().getDisplayName()), typeSize, new BooleanLiteral(String.valueOf(field.isAliased()))); }
private Object getPrestoObject(TpchColumn<E> column, Type type) { if (type.getJavaType() == long.class) { return getLong(column); } else if (type.getJavaType() == double.class) { return getDouble(column); } else if (type.getJavaType() == Slice.class) { return getSlice(column); } else { throw new PrestoException(NOT_SUPPORTED, format("Unsupported column type %s", type.getDisplayName())); } }
@TypeParameter("T") @SqlType(StandardTypes.VARCHAR) public static Slice typeof( @TypeParameter("T") Type type, @SqlNullable @SqlType("T") Object value) { return utf8Slice(type.getDisplayName()); }
protected String toSqlType(Type type) { if (isVarcharType(type)) { VarcharType varcharType = (VarcharType) type; if (varcharType.isUnbounded()) { return "varchar"; } return "varchar(" + varcharType.getLengthSafe() + ")"; } if (type instanceof CharType) { if (((CharType) type).getLength() == CharType.MAX_LENGTH) { return "char"; } return "char(" + ((CharType) type).getLength() + ")"; } if (type instanceof DecimalType) { return format("decimal(%s, %s)", ((DecimalType) type).getPrecision(), ((DecimalType) type).getScale()); } String sqlType = SQL_TYPES.get(type); if (sqlType != null) { return sqlType; } throw new PrestoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName()); }
private static void addTypeRow(Builder builder, Type type) { builder.addRow( type.getDisplayName(), jdbcDataType(type), columnSize(type), null, null, null, DatabaseMetaData.typeNullable, false, type.isComparable() ? DatabaseMetaData.typeSearchable : DatabaseMetaData.typePredNone, null, false, null, null, 0, 0, null, null, numPrecRadix(type)); }
@Setup public void setup() { Type type = TYPE_MAP.get(this.type); for (int i = 0; i < columnCount; i++) { Symbol symbol = new Symbol(type.getDisplayName().toLowerCase(ENGLISH) + i); symbolTypes.put(symbol, type); sourceLayout.put(symbol, i); } List<RowExpression> projections = getProjections(type); types = projections.stream().map(RowExpression::getType).collect(toList()); MetadataManager metadata = createTestMetadataManager(); PageFunctionCompiler pageFunctionCompiler = new PageFunctionCompiler(metadata, 0); inputPage = createPage(types, dictionaryBlocks); pageProcessor = new ExpressionCompiler(metadata, pageFunctionCompiler).compilePageProcessor(Optional.of(getFilter(type)), projections).get(); recordSet = new PageRecordSet(types, inputPage); cursorProcessor = new ExpressionCompiler(metadata, pageFunctionCompiler).compileCursorProcessor(Optional.of(getFilter(type)), projections, "key").get(); }