@Override public boolean equals(Object o) { if (!(o instanceof Field)) { return false; } Field other = (Field) o; return Objects.equals(getName(), other.getName()) && Objects.equals(getDescription(), other.getDescription()) && Objects.equals(getType(), other.getType()) && Objects.equals(getNullable(), other.getNullable()); }
@Override public int hashCode() { return Objects.hash(getName(), getDescription(), getType(), getNullable()); } }
private static List<TableFieldSchema> toTableFieldSchema(Schema schema) { List<TableFieldSchema> fields = new ArrayList<>(schema.getFieldCount()); for (Field schemaField : schema.getFields()) { FieldType type = schemaField.getType(); TableFieldSchema field = new TableFieldSchema().setName(schemaField.getName()); if (schemaField.getDescription() != null && !"".equals(schemaField.getDescription())) { field.setDescription(schemaField.getDescription()); } if (!schemaField.getNullable()) { field.setMode(Mode.REQUIRED.toString()); } if (TypeName.ARRAY == type.getTypeName()) { type = type.getCollectionElementType(); field.setMode(Mode.REPEATED.toString()); } if (TypeName.ROW == type.getTypeName()) { Schema subType = type.getRowSchema(); field.setFields(toTableFieldSchema(subType)); } field.setType(toStandardSQLTypeName(type).toString()); fields.add(field); } return fields; }
private void unparseColumn(SqlWriter writer, Schema.Field column) { writer.sep(","); writer.identifier(column.getName()); writer.identifier(CalciteUtils.toSqlTypeName(column.getType()).name()); if (column.getNullable() != null && !column.getNullable()) { writer.keyword("NOT NULL"); } if (column.getDescription() != null) { writer.keyword("COMMENT"); writer.literal(column.getDescription()); } }