Skip to content

Commit

Permalink
Use builder methof initalizing immutable map in integration test (apa…
Browse files Browse the repository at this point in the history
  • Loading branch information
eaugene authored Sep 18, 2023
1 parent a8411c0 commit b1b070f
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,129 +45,102 @@ public final class TblToAvro {
private static final String STRING_TYPE = "string";
private static final String FOLDER_PATH = "/Users/haitaozhang/Downloads/TPC-H-V3.0.1/dbgen/";
private static final String TBL_FILE_SUFFIX = ".tbl";
private static final Map<String, String[]> TABLE_NAME_FIELDS_MAP =
ImmutableMap.of(
// One example record:
// {"c_custkey":{"long":1},"c_name":{"string":"Customer#000000001"},
// "c_address":{"string":"IVhzIApeRb ot,c,E"},"c_nationkey":{"long":15},
// "c_phone":{"string":"25-989-741-2988"},"c_acctbal":{"double":711.56},"c_mktsegment":{"string":"BUILDING"},
// "c_comment":{"string":"to the even, regular platelets. regular, ironic epitaphs nag e"}}
"customer",
new String[]{
"c_custkey", LONG_TYPE,
"c_name", STRING_TYPE,
"c_address", STRING_TYPE,
"c_nationkey", LONG_TYPE,
"c_phone", STRING_TYPE,
"c_acctbal", DOUBLE_TYPE,
"c_mktsegment", STRING_TYPE,
"c_comment", STRING_TYPE},
// One example record:
// {"l_orderkey":{"long":600000},"l_partkey":{"long":12916},"l_suppkey":{"long":917},
// "l_linenumber":{"long":2},"l_quantity":{"long":1},"l_extendedprice":{"double":1828.91},
// "l_discount":{"double":0.03},"l_tax":{"double":0.0},"l_returnflag":{"string":"N"},
// "l_linestatus":{"string":"O"},"l_shipdate":{"string":"1998-04-13"},"l_commitdate":{"string":"1998-05-24"},
// "l_receiptdate":{"string":"1998-04-30"},"l_shipinstruct":{"string":"DELIVER IN PERSON"},
// "l_shipmode":{"string":"RAIL"},"l_comment":{"string":" wake braids. "}}
"lineitem",
new String[]{
"l_orderkey", LONG_TYPE,
"l_partkey", LONG_TYPE,
"l_suppkey", LONG_TYPE,
"l_linenumber", LONG_TYPE,
"l_quantity", LONG_TYPE,
"l_extendedprice", DOUBLE_TYPE,
"l_discount", DOUBLE_TYPE,
"l_tax", DOUBLE_TYPE,
"l_returnflag", STRING_TYPE,
"l_linestatus", STRING_TYPE,
"l_shipdate", STRING_TYPE,
"l_commitdate", STRING_TYPE,
"l_receiptdate", STRING_TYPE,
"l_shipinstruct", STRING_TYPE,
"l_shipmode", STRING_TYPE,
"l_comment", STRING_TYPE},
// One example record:
// {"n_nationkey":{"long":0},"n_name":{"string":"ALGERIA"},"n_regionkey":{"long":0},
// "n_comment":{"string":" haggle. carefully final deposits detect slyly agai"}}
"nation",
new String[]{
"n_nationkey", LONG_TYPE,
"n_name", STRING_TYPE,
"n_regionkey", LONG_TYPE,
"n_comment", STRING_TYPE},
// One example record:
// {"o_orderkey":{"long":1},"o_custkey":{"long":370},"o_orderstatus":{"string":"O"},
// "o_totalprice":{"double":173665.47},"o_orderdate":{"string":"1996-01-02"},
// "o_orderpriority":{"string":"5-LOW"},"o_clerk":{"string":"Clerk#000000951"},"o_shippriority":{"long":0},
// "o_comment":{"string":"ly final dependencies: slyly bold "}}
"orders",
new String[]{
"o_orderkey", LONG_TYPE,
"o_custkey", LONG_TYPE,
"o_orderstatus", STRING_TYPE,
"o_totalprice", DOUBLE_TYPE,
"o_orderdate", STRING_TYPE,
"o_orderpriority", STRING_TYPE,
"o_clerk", STRING_TYPE,
"o_shippriority", LONG_TYPE,
"o_comment", STRING_TYPE},
// One example record:
// {"p_partkey":{"long":1},"p_name":{"string":"goldenrod lavender spring chocolate lace"},
// "p_mfgr":{"string":"Manufacturer#1"},"p_brand":{"string":"Brand#13"},
// "p_type":{"string":"PROMO BRUSHED STEEL"},"p_size":{"long":7},"p_container":{"string":"JUMBO PKG"},
// "p_retailprice":{"double":901.0},"p_comment":{"string":"ly final dependencies: slyly bold "}}
"part",
new String[]{
"p_partkey", LONG_TYPE,
"p_name", STRING_TYPE,
"p_mfgr", STRING_TYPE,
"p_brand", STRING_TYPE,
"p_type", STRING_TYPE,
"p_size", LONG_TYPE,
"p_container", STRING_TYPE,
"p_retailprice", DOUBLE_TYPE,
"p_comment", STRING_TYPE},
// One example record:
// {"ps_partkey":{"long":1},"ps_suppkey":{"long":2},"ps_availqty":{"long":997},
// "ps_supplycost":{"double":6.02},"ps_comment":{"string":"ly final dependencies: slyly bold "}}
"partsupp",
new String[]{
"ps_partkey", LONG_TYPE,
"ps_suppkey", LONG_TYPE,
"ps_availqty", LONG_TYPE,
"ps_supplycost", DOUBLE_TYPE,
"ps_comment", STRING_TYPE},
// One example record:
// {"r_regionkey":{"long":0},"r_name":{"string":"AFRICA"},"r_comment":{"string":"lar deposits. blithe"}}
"region",
new String[]{
"r_regionkey", LONG_TYPE,
"r_name", STRING_TYPE,
"r_comment", STRING_TYPE},
// One example record:
// {"s_suppkey":{"long":1},"s_name":{"string":"Supplier#000000001"},
// "s_address":{"string":" N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ"},"s_nationkey":{"long":15},
// "s_phone":{"string":"25-989-741-2988"},"s_acctbal":{"double":711.56},
// "s_comment":{"string":" deposits eat slyly ironic, even instructions. express foxes detect slyly.
// blithely even accounts abov"}}
"supplier",
new String[]{
"s_suppkey", LONG_TYPE,
"s_name", STRING_TYPE,
"s_address", STRING_TYPE,
"s_nationkey", LONG_TYPE,
"s_phone", STRING_TYPE,
"s_acctbal", DOUBLE_TYPE,
"s_comment", STRING_TYPE});
private static final Map<String, String[]> TABLE_NAME_FIELDS_MAP = ImmutableMap.<String, String[]>builder().
// One example record:
// {"c_custkey":{"long":1},"c_name":{"string":"Customer#000000001"},
// "c_address":{"string":"IVhzIApeRb ot,c,E"},"c_nationkey":{"long":15},
// "c_phone":{"string":"25-989-741-2988"},"c_acctbal":{"double":711.56},"c_mktsegment":{"string":"BUILDING"},
// "c_comment":{"string":"to the even, regular platelets. regular, ironic epitaphs nag e"}}
put("customer",
new String[] {
"c_custkey", LONG_TYPE, "c_name", STRING_TYPE, "c_address", STRING_TYPE, "c_nationkey", LONG_TYPE, "c_phone",
STRING_TYPE, "c_acctbal", DOUBLE_TYPE, "c_mktsegment", STRING_TYPE, "c_comment", STRING_TYPE
}).

// One example record:
// {"l_orderkey":{"long":600000},"l_partkey":{"long":12916},"l_suppkey":{"long":917},
// "l_linenumber":{"long":2},"l_quantity":{"long":1},"l_extendedprice":{"double":1828.91},
// "l_discount":{"double":0.03},"l_tax":{"double":0.0},"l_returnflag":{"string":"N"},
// "l_linestatus":{"string":"O"},"l_shipdate":{"string":"1998-04-13"},"l_commitdate":{"string":"1998-05-24"},
// "l_receiptdate":{"string":"1998-04-30"},"l_shipinstruct":{"string":"DELIVER IN PERSON"},
// "l_shipmode":{"string":"RAIL"},"l_comment":{"string":" wake braids. "}}
put("lineitem",
new String[] {
"l_orderkey", LONG_TYPE, "l_partkey", LONG_TYPE, "l_suppkey", LONG_TYPE, "l_linenumber", LONG_TYPE, "l_quantity",
LONG_TYPE, "l_extendedprice", DOUBLE_TYPE, "l_discount", DOUBLE_TYPE, "l_tax", DOUBLE_TYPE, "l_returnflag",
STRING_TYPE, "l_linestatus", STRING_TYPE, "l_shipdate", STRING_TYPE, "l_commitdate", STRING_TYPE,
"l_receiptdate", STRING_TYPE, "l_shipinstruct", STRING_TYPE, "l_shipmode", STRING_TYPE, "l_comment", STRING_TYPE
}).

// One example record:
// {"n_nationkey":{"long":0},"n_name":{"string":"ALGERIA"},"n_regionkey":{"long":0},
// "n_comment":{"string":" haggle. carefully final deposits detect slyly agai"}}
put("nation",
new String[] {
"n_nationkey", LONG_TYPE, "n_name", STRING_TYPE, "n_regionkey", LONG_TYPE, "n_comment", STRING_TYPE
}).

// One example record:
// {"o_orderkey":{"long":1},"o_custkey":{"long":370},"o_orderstatus":{"string":"O"},
// "o_totalprice":{"double":173665.47},"o_orderdate":{"string":"1996-01-02"},
// "o_orderpriority":{"string":"5-LOW"},"o_clerk":{"string":"Clerk#000000951"},"o_shippriority":{"long":0},
// "o_comment":{"string":"ly final dependencies: slyly bold "}}
put("orders",
new String[] {
"o_orderkey", LONG_TYPE, "o_custkey", LONG_TYPE, "o_orderstatus", STRING_TYPE, "o_totalprice", DOUBLE_TYPE,
"o_orderdate", STRING_TYPE, "o_orderpriority", STRING_TYPE, "o_clerk", STRING_TYPE, "o_shippriority",
LONG_TYPE, "o_comment", STRING_TYPE
}).

// One example record:
// {"p_partkey":{"long":1},"p_name":{"string":"goldenrod lavender spring chocolate lace"},
// "p_mfgr":{"string":"Manufacturer#1"},"p_brand":{"string":"Brand#13"},
// "p_type":{"string":"PROMO BRUSHED STEEL"},"p_size":{"long":7},"p_container":{"string":"JUMBO PKG"},
// "p_retailprice":{"double":901.0},"p_comment":{"string":"ly final dependencies: slyly bold "}}
put("part",
new String[] {
"p_partkey", LONG_TYPE, "p_name", STRING_TYPE, "p_mfgr", STRING_TYPE, "p_brand", STRING_TYPE, "p_type",
STRING_TYPE, "p_size", LONG_TYPE, "p_container", STRING_TYPE, "p_retailprice", DOUBLE_TYPE, "p_comment",
STRING_TYPE
}).

// One example record:
// {"ps_partkey":{"long":1},"ps_suppkey":{"long":2},"ps_availqty":{"long":997},
// "ps_supplycost":{"double":6.02},"ps_comment":{"string":"ly final dependencies: slyly bold "}}
put("partsupp",
new String[] {
"ps_partkey", LONG_TYPE, "ps_suppkey", LONG_TYPE, "ps_availqty", LONG_TYPE, "ps_supplycost", DOUBLE_TYPE,
"ps_comment", STRING_TYPE
}).

// One example record:
// {"r_regionkey":{"long":0},"r_name":{"string":"AFRICA"},"r_comment":{"string":"lar deposits. blithe"}}
put("region",
new String[] {
"r_regionkey", LONG_TYPE, "r_name", STRING_TYPE, "r_comment", STRING_TYPE
}).

// One example record:
// {"s_suppkey":{"long":1},"s_name":{"string":"Supplier#000000001"},
// "s_address":{"string":" N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ"},"s_nationkey":{"long":15},
// "s_phone":{"string":"25-989-741-2988"},"s_acctbal":{"double":711.56},
// "s_comment":{"string":" deposits eat slyly ironic, even instructions. express foxes detect slyly.
// blithely even accounts abov"}}
put("supplier",
new String[] {
"s_suppkey", LONG_TYPE, "s_name", STRING_TYPE, "s_address", STRING_TYPE, "s_nationkey", LONG_TYPE, "s_phone",
STRING_TYPE, "s_acctbal", DOUBLE_TYPE, "s_comment", STRING_TYPE
}).
build();

private TblToAvro() {
}

public static void main(String[] args) throws IOException {
public static void main(String[] args)
throws IOException {
// String tpchTblFileFolder = args[0];
String tpchTblFileFolder = FOLDER_PATH;
for (Map.Entry<String, String[]> entry: TABLE_NAME_FIELDS_MAP.entrySet()) {
for (Map.Entry<String, String[]> entry : TABLE_NAME_FIELDS_MAP.entrySet()) {
String tableName = entry.getKey();
String[] fieldsAndTypes = entry.getValue();
SchemaBuilder.FieldAssembler<Schema> schemaFields = SchemaBuilder.record(tableName).fields();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,82 +43,82 @@ public class TblToAvroMultiValue {
private static final String STRING_TYPE = "string";
private static final String FOLDER_PATH = "/Users/saurabh.dubey/Documents/workspace/stuff/tpch/data/s001/";
private static final String TBL_FILE_SUFFIX = ".tbl";
private static final Map<String, String[]> TABLE_NAME_FIELDS_MAP = ImmutableMap.of(
private static final Map<String, String[]> TABLE_NAME_FIELDS_MAP = ImmutableMap.<String, String[]>builder().
// One example record:
// {"c_custkey":{"long":1},"c_name":{"string":"Customer#000000001"},
// "c_address":{"string":"IVhzIApeRb ot,c,E"},"c_nationkey":{"long":15},
// "c_phone":{"string":"25-989-741-2988"},"c_acctbal":{"double":711.56},"c_mktsegment":{"string":"BUILDING"},
// "c_comment":{"string":"to the even, regular platelets. regular, ironic epitaphs nag e"}}
"customer", new String[]{
put("customer", new String[]{
"c_custkey", LONG_TYPE, "false", "c_name", STRING_TYPE, "true", "c_address", STRING_TYPE, "true",
"c_nationkey", LONG_TYPE, "false", "c_phone", STRING_TYPE, "false", "c_acctbal", DOUBLE_TYPE, "false",
"c_mktsegment", STRING_TYPE, "true", "c_comment", STRING_TYPE, "false"
},
}).
// One example record:
// {"l_orderkey":{"long":600000},"l_partkey":{"long":12916},"l_suppkey":{"long":917},
// "l_linenumber":{"long":2},"l_quantity":{"long":1},"l_extendedprice":{"double":1828.91},
// "l_discount":{"double":0.03},"l_tax":{"double":0.0},"l_returnflag":{"string":"N"},
// "l_linestatus":{"string":"O"},"l_shipdate":{"string":"1998-04-13"},"l_commitdate":{"string":"1998-05-24"},
// "l_receiptdate":{"string":"1998-04-30"},"l_shipinstruct":{"string":"DELIVER IN PERSON"},
// "l_shipmode":{"string":"RAIL"},"l_comment":{"string":" wake braids. "}}
"lineitem", new String[]{
put("lineitem", new String[]{
"l_orderkey", LONG_TYPE, "false", "l_partkey", LONG_TYPE, "false", "l_suppkey", LONG_TYPE, "false",
"l_linenumber", LONG_TYPE, "true", "l_quantity", LONG_TYPE, "true", "l_extendedprice", DOUBLE_TYPE, "true",
"l_discount", DOUBLE_TYPE, "true", "l_tax", DOUBLE_TYPE, "false", "l_returnflag", STRING_TYPE, "false",
"l_linestatus", STRING_TYPE, "false", "l_shipdate", STRING_TYPE, "false", "l_commitdate", STRING_TYPE,
"false", "l_receiptdate", STRING_TYPE, "false", "l_shipinstruct", STRING_TYPE, "false", "l_shipmode",
STRING_TYPE, "false", "l_comment", STRING_TYPE, "false"
},
}).
// One example record:
// {"n_nationkey":{"long":0},"n_name":{"string":"ALGERIA"},"n_regionkey":{"long":0},
// "n_comment":{"string":" haggle. carefully final deposits detect slyly agai"}}
"nation", new String[]{
put("nation", new String[]{
"n_nationkey", LONG_TYPE, "false", "n_name", STRING_TYPE, "true", "n_regionkey", LONG_TYPE, "false",
"n_comment", STRING_TYPE, "false"
},
}).
// One example record:
// {"o_orderkey":{"long":1},"o_custkey":{"long":370},"o_orderstatus":{"string":"O"},
// "o_totalprice":{"double":173665.47},"o_orderdate":{"string":"1996-01-02"},
// "o_orderpriority":{"string":"5-LOW"},"o_clerk":{"string":"Clerk#000000951"},"o_shippriority":{"long":0},
// "o_comment":{"string":"ly final dependencies: slyly bold "}}
"orders", new String[]{
put("orders", new String[]{
"o_orderkey", LONG_TYPE, "false", "o_custkey", LONG_TYPE, "false", "o_orderstatus", STRING_TYPE, "true",
"o_totalprice", DOUBLE_TYPE, "true", "o_orderdate", STRING_TYPE, "false", "o_orderpriority", STRING_TYPE,
"false", "o_clerk", STRING_TYPE, "true", "o_shippriority", LONG_TYPE, "true", "o_comment", STRING_TYPE, "true"
},
}).
// One example record:
// {"p_partkey":{"long":1},"p_name":{"string":"goldenrod lavender spring chocolate lace"},
// "p_mfgr":{"string":"Manufacturer#1"},"p_brand":{"string":"Brand#13"},
// "p_type":{"string":"PROMO BRUSHED STEEL"},"p_size":{"long":7},"p_container":{"string":"JUMBO PKG"},
// "p_retailprice":{"double":901.0},"p_comment":{"string":"ly final dependencies: slyly bold "}}
"part", new String[]{
put("part", new String[]{
"p_partkey", LONG_TYPE, "false", "p_name", STRING_TYPE, "true", "p_mfgr", STRING_TYPE, "true", "p_brand",
STRING_TYPE, "true", "p_type", STRING_TYPE, "true", "p_size", LONG_TYPE, "true", "p_container", STRING_TYPE,
"true", "p_retailprice", DOUBLE_TYPE, "true", "p_comment", STRING_TYPE, "true"
},
}).
// One example record:
// {"ps_partkey":{"long":1},"ps_suppkey":{"long":2},"ps_availqty":{"long":997},
// "ps_supplycost":{"double":6.02},"ps_comment":{"string":"ly final dependencies: slyly bold "}}
"partsupp", new String[]{
put("partsupp", new String[]{
"ps_partkey", LONG_TYPE, "false", "ps_suppkey", LONG_TYPE, "false", "ps_availqty", LONG_TYPE, "true",
"ps_supplycost", DOUBLE_TYPE, "true", "ps_comment", STRING_TYPE, "true"
},
}).
// One example record:
// {"r_regionkey":{"long":0},"r_name":{"string":"AFRICA"},"r_comment":{"string":"lar deposits. blithe"}}
"region", new String[]{
put("region", new String[]{
"r_regionkey", LONG_TYPE, "false", "r_name", STRING_TYPE, "true", "r_comment", STRING_TYPE, "false"
},
}).
// One example record:
// {"s_suppkey":{"long":1},"s_name":{"string":"Supplier#000000001"},
// "s_address":{"string":" N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ"},"s_nationkey":{"long":15},
// "s_phone":{"string":"25-989-741-2988"},"s_acctbal":{"double":711.56},
// "s_comment":{"string":" deposits eat slyly ironic, even instructions. express foxes detect slyly.
// blithely even accounts abov"}}
"supplier", new String[]{
put("supplier", new String[]{
"s_suppkey", LONG_TYPE, "false", "s_name", STRING_TYPE, "true", "s_address", STRING_TYPE, "true",
"s_nationkey", LONG_TYPE, "false", "s_phone", STRING_TYPE, "true", "s_acctbal", DOUBLE_TYPE, "false",
"s_comment", STRING_TYPE, "false"
});
}).build();

private TblToAvroMultiValue() {
}
Expand Down

0 comments on commit b1b070f

Please sign in to comment.