@Test public void testBuildSchema() { List<Field> arrayList = Arrays.asList( new Field("String", String.class), new Field("Byte", Byte.class), new Field("Short", Short.class), new Field("Integer", Integer.class), new Field("Long", Long.class), new Field("Date", Date.class), new Field("Float", Float.class), new Field("Double", Double.class), new Field("BigDecimal", BigDecimal.class), new Field("Boolean", Boolean.class), new Field("byte[]", byte[].class)); String actual = "message row { optional binary String (UTF8); " + "optional INT32 Byte; optional INT32 Short; " + "optional INT32 Integer; optional INT64 Long; " + "optional INT64 Date; optional FLOAT Float; " + "optional DOUBLE Double; optional DOUBLE BigDecimal; " + "optional BOOLEAN Boolean; optional binary byte[]; } "; Assert.assertEquals(actual, ParquetUtil.buildSchema(arrayList)); }
public static String buildSchema(List<Field> fields) { StringBuilder sb = new StringBuilder("message row { "); for (Field field : fields) { String fieldName = field.getName(); Class<?> type = field.getJavaTypeClass(); switch (type.getSimpleName()) { case "String": sb.append("optional binary ").append(fieldName).append(" (UTF8); "); break; case "Byte": case "Short": case "Integer": sb.append("optional INT32 ").append(fieldName).append("; "); break; case "Long": case "Date": sb.append("optional INT64 ").append(fieldName).append("; "); break; case "Float": sb.append("optional FLOAT ").append(fieldName).append("; "); break; case "Double": case "BigDecimal": sb.append("optional DOUBLE ").append(fieldName).append("; "); break; case "Boolean": sb.append("optional BOOLEAN ").append(fieldName).append("; "); break; case "byte[]": sb.append("optional binary ").append(fieldName).append("; "); break; case "Map": throw new UnsupportedOperationException("this type[Map] have't support!"); default: throw new UnsupportedOperationException("this " + type + " have't support!"); } } sb.append("} "); return sb.toString(); }
ParquetUtil { public static String buildSchema(List<Field> fields) { StringBuilder sb = new StringBuilder("message row { "); for (Field field : fields) { String fieldName = field.getName(); Class<?> type = field.getJavaTypeClass(); switch (type.getSimpleName()) { case "String": sb.append("optional binary ").append(fieldName).append(" (UTF8); "); break; case "Byte": case "Short": case "Integer": sb.append("optional INT32 ").append(fieldName).append("; "); break; case "Long": case "Date": sb.append("optional INT64 ").append(fieldName).append("; "); break; case "Float": sb.append("optional FLOAT ").append(fieldName).append("; "); break; case "Double": case "BigDecimal": sb.append("optional DOUBLE ").append(fieldName).append("; "); break; case "Boolean": sb.append("optional BOOLEAN ").append(fieldName).append("; "); break; case "byte[]": sb.append("optional binary ").append(fieldName).append("; "); break; case "Map": throw new UnsupportedOperationException("this type[Map] have't support!"); default: throw new UnsupportedOperationException("this " + type + " have't support!"); } } sb.append("} "); return sb.toString(); } }
ParquetUtil { public static String buildSchema(List<Field> fields) { StringBuilder sb = new StringBuilder("message row { "); for (Field field : fields) { String fieldName = field.getName(); Class<?> type = field.getJavaTypeClass(); switch (type.getSimpleName()) { case "String": sb.append("optional binary ").append(fieldName).append(" (UTF8); "); break; case "Byte": case "Short": case "Integer": sb.append("optional INT32 ").append(fieldName).append("; "); break; case "Long": case "Date": sb.append("optional INT64 ").append(fieldName).append("; "); break; case "Float": sb.append("optional FLOAT ").append(fieldName).append("; "); break; case "Double": case "BigDecimal": sb.append("optional DOUBLE ").append(fieldName).append("; "); break; case "Boolean": sb.append("optional BOOLEAN ").append(fieldName).append("; "); break; case "byte[]": sb.append("optional binary ").append(fieldName).append("; "); break; case "Map": throw new UnsupportedOperationException("this type[Map] have't support!"); default: throw new UnsupportedOperationException("this " + type + " have't support!"); } } sb.append("} "); return sb.toString(); } private  ParquetUtil(); }
ParquetUtil { public static String buildSchema(List<Field> fields) { StringBuilder sb = new StringBuilder("message row { "); for (Field field : fields) { String fieldName = field.getName(); Class<?> type = field.getJavaTypeClass(); switch (type.getSimpleName()) { case "String": sb.append("optional binary ").append(fieldName).append(" (UTF8); "); break; case "Byte": case "Short": case "Integer": sb.append("optional INT32 ").append(fieldName).append("; "); break; case "Long": case "Date": sb.append("optional INT64 ").append(fieldName).append("; "); break; case "Float": sb.append("optional FLOAT ").append(fieldName).append("; "); break; case "Double": case "BigDecimal": sb.append("optional DOUBLE ").append(fieldName).append("; "); break; case "Boolean": sb.append("optional BOOLEAN ").append(fieldName).append("; "); break; case "byte[]": sb.append("optional binary ").append(fieldName).append("; "); break; case "Map": throw new UnsupportedOperationException("this type[Map] have't support!"); default: throw new UnsupportedOperationException("this " + type + " have't support!"); } } sb.append("} "); return sb.toString(); } private  ParquetUtil(); static String buildSchema(List<Field> fields); }
ParquetUtil { public static String buildSchema(List<Field> fields) { StringBuilder sb = new StringBuilder("message row { "); for (Field field : fields) { String fieldName = field.getName(); Class<?> type = field.getJavaTypeClass(); switch (type.getSimpleName()) { case "String": sb.append("optional binary ").append(fieldName).append(" (UTF8); "); break; case "Byte": case "Short": case "Integer": sb.append("optional INT32 ").append(fieldName).append("; "); break; case "Long": case "Date": sb.append("optional INT64 ").append(fieldName).append("; "); break; case "Float": sb.append("optional FLOAT ").append(fieldName).append("; "); break; case "Double": case "BigDecimal": sb.append("optional DOUBLE ").append(fieldName).append("; "); break; case "Boolean": sb.append("optional BOOLEAN ").append(fieldName).append("; "); break; case "byte[]": sb.append("optional binary ").append(fieldName).append("; "); break; case "Map": throw new UnsupportedOperationException("this type[Map] have't support!"); default: throw new UnsupportedOperationException("this " + type + " have't support!"); } } sb.append("} "); return sb.toString(); } private  ParquetUtil(); static String buildSchema(List<Field> fields);  }