/** * @return the FieldType of LONG with the given name */ public static FieldType longType(String name) { return new FieldType(name, FieldType.Type.LONG); }
/** * @return the type of the field */ public FieldType.Type getFieldType() { return fieldType.getType(); }
/** * @return the field name */ public String getName() { return fieldType.getName(); }
@Override public int hashCode() { if (fieldType.getType() == FieldType.Type.BYTES) { return Objects.hash(fieldType, Bytes.hashCode((byte[]) value)); } return Objects.hash(fieldType, value); }
private String getCreateStatement(StructuredTableSpecification specification) { StringBuilder createStmt = new StringBuilder(); createStmt.append("CREATE TABLE ").append(specification.getTableId().getName()).append(" ("); // append the columns with sql type createStmt.append( specification.getFieldTypes().stream() .map(f -> f.getName() + " " + getPostgresSqlType(f)) .collect(Collectors.joining(",")) ); // append primary key createStmt.append(", PRIMARY KEY (").append(Joiner.on(",").join(specification.getPrimaryKeys())).append("))"); return createStmt.toString(); }
/** * @return the FieldType of FLOAT with the given name */ public static FieldType floatType(String name) { return new FieldType(name, FieldType.Type.FLOAT); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Field field = (Field) o; if (!Objects.equals(fieldType, field.fieldType)) { return false; } if (fieldType.getType() == FieldType.Type.BYTES) { return Bytes.equals((byte[]) value, (byte[]) field.getValue()); } return Objects.equals(value, field.value); }
/** * @return the FieldType of INTEGER with the given name */ public static FieldType intType(String name) { return new FieldType(name, FieldType.Type.INTEGER); }
/** * @return the FieldType of DOUBLE with the given name */ public static FieldType doubleType(String name) { return new FieldType(name, FieldType.Type.DOUBLE); }
/** * @return the FieldType of STRING with the given name */ public static FieldType stringType(String name) { return new FieldType(name, FieldType.Type.STRING); }
/** * @return the FieldType of BYTES with the given name */ public static FieldType bytesType(String name) { return new FieldType(name, FieldType.Type.BYTES); }
/** * Create a field with string value. * * @param name name of the field * @param value value of the field * @return a field with type string */ public static Field<String> stringField(String name, @Nullable String value) { return new Field<>(new FieldType(name, FieldType.Type.STRING), value); }
/** * Create a field with float value. * * @param name name of the field * @param value value of the field * @return a field with type float */ public static Field<Float> floatField(String name, @Nullable Float value) { return new Field<>(new FieldType(name, FieldType.Type.FLOAT), value); }
/** * Create a field with integer value. * * @param name name of the field * @param value value of the field * @return a field with type integer */ public static Field<Integer> intField(String name, @Nullable Integer value) { return new Field<>(new FieldType(name, FieldType.Type.INTEGER), value); }
/** * Create a field with long value. * * @param name name of the field * @param value value of the field * @return a field with type long */ public static Field<Long> longField(String name, @Nullable Long value) { return new Field<>(new FieldType(name, FieldType.Type.LONG), value); }
/** * Create a field with byte[] value. * * @param name name of the field * @param value value of the field * @return a field with type BYTES */ public static Field<byte[]> bytesField(String name, @Nullable byte[] value) { return new Field<>(new FieldType(name, FieldType.Type.BYTES), value); }
/** * Create a field with double value. * * @param name name of the field * @param value value of the field * @return a field with type double */ public static Field<Double> doubleField(String name, @Nullable Double value) { return new Field<>(new FieldType(name, FieldType.Type.DOUBLE), value); }