/** * Auto-generates the key struct for composite keys * * @param compositeKeyParts map of composite key part name to its type. Usually this would be * provided by the custom implementation of {@link HBaseCompositeKey composite key} * @param sb StringBuilder object to construct the struct * */ private static void generateKeyStruct(Map<String, String> compositeKeyParts, StringBuilder sb) { sb.append("struct<"); for (Entry<String, String> entry : compositeKeyParts.entrySet()) { sb.append(entry.getKey()).append(":").append(entry.getValue()).append(","); } // trim the trailing "," trim(sb); sb.append(">"); }
/** * Auto-generates the key struct for composite keys * * @param compositeKeyTypes comma separated list of composite key types in order * @param sb StringBuilder object to construct the struct * */ private static void generateKeyStruct(String compositeKeyTypes, StringBuilder sb) { sb.append("struct<"); // composite key types is a comma separated list of different parts of the // composite keys in // order in which they appear in the key String[] keyTypes = compositeKeyTypes.split(","); for (int i = 0; i < keyTypes.length; i++) { sb.append("col" + i).append(":").append(keyTypes[i]).append(StringUtils.COMMA_STR); } // trim the trailing "," trim(sb); sb.append(">"); }
/** * Auto-generate the avro struct from schema * * @param schema schema for the avro struct * @param sb StringBuilder to hold the generated struct * @throws SerDeException if something goes wrong while generating the struct * */ private static void generateAvroStructFromSchema(Schema schema, StringBuilder sb) throws SerDeException { AvroObjectInspectorGenerator avig = new AvroObjectInspectorGenerator(schema); sb.append("struct<"); // Get the column names and their corresponding types List<String> columnNames = avig.getColumnNames(); List<TypeInfo> columnTypes = avig.getColumnTypes(); if (columnNames.size() != columnTypes.size()) { throw new AssertionError("The number of column names should be the same as column types"); } for (int i = 0; i < columnNames.size(); i++) { sb.append(columnNames.get(i)); sb.append(":"); sb.append(columnTypes.get(i).getTypeName()); sb.append(","); } trim(sb).append(">"); }
/** * Auto-generates the key struct for composite keys * * @param compositeKeyParts map of composite key part name to its type. Usually this would be * provided by the custom implementation of {@link HBaseCompositeKey composite key} * @param sb StringBuilder object to construct the struct * */ private static void generateKeyStruct(Map<String, String> compositeKeyParts, StringBuilder sb) { sb.append("struct<"); for (Entry<String, String> entry : compositeKeyParts.entrySet()) { sb.append(entry.getKey()).append(":").append(entry.getValue()).append(","); } // trim the trailing "," trim(sb); sb.append(">"); }
/** * Auto-generates the key struct for composite keys * * @param compositeKeyTypes comma separated list of composite key types in order * @param sb StringBuilder object to construct the struct * */ private static void generateKeyStruct(String compositeKeyTypes, StringBuilder sb) { sb.append("struct<"); // composite key types is a comma separated list of different parts of the // composite keys in // order in which they appear in the key String[] keyTypes = compositeKeyTypes.split(","); for (int i = 0; i < keyTypes.length; i++) { sb.append("col" + i).append(":").append(keyTypes[i]).append(StringUtils.COMMA_STR); } // trim the trailing "," trim(sb); sb.append(">"); }
/** * Auto-generate the avro struct from schema * * @param schema schema for the avro struct * @param sb StringBuilder to hold the generated struct * @throws SerDeException if something goes wrong while generating the struct * */ private static void generateAvroStructFromSchema(Schema schema, StringBuilder sb) throws SerDeException { AvroObjectInspectorGenerator avig = new AvroObjectInspectorGenerator(schema); sb.append("struct<"); // Get the column names and their corresponding types List<String> columnNames = avig.getColumnNames(); List<TypeInfo> columnTypes = avig.getColumnTypes(); if (columnNames.size() != columnTypes.size()) { throw new AssertionError("The number of column names should be the same as column types"); } for (int i = 0; i < columnNames.size(); i++) { sb.append(columnNames.get(i)); sb.append(":"); sb.append(columnTypes.get(i).getTypeName()); sb.append(","); } trim(sb).append(">"); }