Skip to content

Commit ddcbaa7

Browse files
committed
apacheGH-50830: [C++][Parquet] Use JsonWriter for LogicalType::ToJSON()
I changed the 8 ToJSON() functions so that they now use JsonWriter instead of the old hand build strings. I deleted WriteCrsKeyAndValue since it was no longer needed, and I updated the test files to match the changes made in types.cc
1 parent e611f48 commit ddcbaa7

3 files changed

Lines changed: 133 additions & 119 deletions

File tree

‎cpp/src/parquet/reader_test.cc‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,8 @@ TEST_F(TestJSONWithLocalFile, JSONOutputWithStatistics) {
11111111
"NumberOfRealColumns": "2",
11121112
"NumberOfColumns": "2",
11131113
"Columns": [
1114-
{ "Id": "0", "Name": "a.list.element.list.element.list.element", "PhysicalType": "BYTE_ARRAY", "ConvertedType": "UTF8", "LogicalType": {"Type": "String"} },
1115-
{ "Id": "1", "Name": "b", "PhysicalType": "INT32", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} }
1114+
{ "Id": "0", "Name": "a.list.element.list.element.list.element", "PhysicalType": "BYTE_ARRAY", "ConvertedType": "UTF8", "LogicalType": {"Type":"String"} },
1115+
{ "Id": "1", "Name": "b", "PhysicalType": "INT32", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} }
11161116
],
11171117
"RowGroups": [
11181118
{
@@ -1142,17 +1142,17 @@ TEST_F(TestJSONWithLocalFile, JSONOutput) {
11421142
"NumberOfRealColumns": "11",
11431143
"NumberOfColumns": "11",
11441144
"Columns": [
1145-
{ "Id": "0", "Name": "id", "PhysicalType": "INT32", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} },
1146-
{ "Id": "1", "Name": "bool_col", "PhysicalType": "BOOLEAN", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} },
1147-
{ "Id": "2", "Name": "tinyint_col", "PhysicalType": "INT32", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} },
1148-
{ "Id": "3", "Name": "smallint_col", "PhysicalType": "INT32", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} },
1149-
{ "Id": "4", "Name": "int_col", "PhysicalType": "INT32", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} },
1150-
{ "Id": "5", "Name": "bigint_col", "PhysicalType": "INT64", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} },
1151-
{ "Id": "6", "Name": "float_col", "PhysicalType": "FLOAT", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} },
1152-
{ "Id": "7", "Name": "double_col", "PhysicalType": "DOUBLE", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} },
1153-
{ "Id": "8", "Name": "date_string_col", "PhysicalType": "BYTE_ARRAY", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} },
1154-
{ "Id": "9", "Name": "string_col", "PhysicalType": "BYTE_ARRAY", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} },
1155-
{ "Id": "10", "Name": "timestamp_col", "PhysicalType": "INT96", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} }
1145+
{ "Id": "0", "Name": "id", "PhysicalType": "INT32", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} },
1146+
{ "Id": "1", "Name": "bool_col", "PhysicalType": "BOOLEAN", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} },
1147+
{ "Id": "2", "Name": "tinyint_col", "PhysicalType": "INT32", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} },
1148+
{ "Id": "3", "Name": "smallint_col", "PhysicalType": "INT32", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} },
1149+
{ "Id": "4", "Name": "int_col", "PhysicalType": "INT32", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} },
1150+
{ "Id": "5", "Name": "bigint_col", "PhysicalType": "INT64", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} },
1151+
{ "Id": "6", "Name": "float_col", "PhysicalType": "FLOAT", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} },
1152+
{ "Id": "7", "Name": "double_col", "PhysicalType": "DOUBLE", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} },
1153+
{ "Id": "8", "Name": "date_string_col", "PhysicalType": "BYTE_ARRAY", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} },
1154+
{ "Id": "9", "Name": "string_col", "PhysicalType": "BYTE_ARRAY", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} },
1155+
{ "Id": "10", "Name": "timestamp_col", "PhysicalType": "INT96", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} }
11561156
],
11571157
"RowGroups": [
11581158
{
@@ -1204,7 +1204,7 @@ TEST_F(TestJSONWithLocalFile, JSONOutputFLBA) {
12041204
"NumberOfRealColumns": "1",
12051205
"NumberOfColumns": "1",
12061206
"Columns": [
1207-
{ "Id": "0", "Name": "flba_field", "PhysicalType": "FIXED_LEN_BYTE_ARRAY(4)", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} }
1207+
{ "Id": "0", "Name": "flba_field", "PhysicalType": "FIXED_LEN_BYTE_ARRAY(4)", "ConvertedType": "NONE", "LogicalType": {"Type":"None"} }
12081208
])###";
12091209

12101210
EXPECT_THAT(json_content, testing::HasSubstr(json_contains));

‎cpp/src/parquet/schema_test.cc‎

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,120 +1495,120 @@ TEST(TestLogicalTypeOperation, LogicalTypeRepresentation) {
14951495
};
14961496

14971497
std::vector<ExpectedRepresentation> cases = {
1498-
{UndefinedLogicalType::Make(), "Undefined", R"({"Type": "Undefined"})"},
1499-
{LogicalType::String(), "String", R"({"Type": "String"})"},
1500-
{LogicalType::Map(), "Map", R"({"Type": "Map"})"},
1501-
{LogicalType::List(), "List", R"({"Type": "List"})"},
1502-
{LogicalType::Enum(), "Enum", R"({"Type": "Enum"})"},
1498+
{UndefinedLogicalType::Make(), "Undefined", R"({"Type":"Undefined"})"},
1499+
{LogicalType::String(), "String", R"({"Type":"String"})"},
1500+
{LogicalType::Map(), "Map", R"({"Type":"Map"})"},
1501+
{LogicalType::List(), "List", R"({"Type":"List"})"},
1502+
{LogicalType::Enum(), "Enum", R"({"Type":"Enum"})"},
15031503
{LogicalType::Decimal(10, 4), "Decimal(precision=10, scale=4)",
1504-
R"({"Type": "Decimal", "precision": 10, "scale": 4})"},
1504+
R"({"Type":"Decimal","precision":10,"scale":4})"},
15051505
{LogicalType::Decimal(10), "Decimal(precision=10, scale=0)",
1506-
R"({"Type": "Decimal", "precision": 10, "scale": 0})"},
1507-
{LogicalType::Date(), "Date", R"({"Type": "Date"})"},
1506+
R"({"Type":"Decimal","precision":10,"scale":0})"},
1507+
{LogicalType::Date(), "Date", R"({"Type":"Date"})"},
15081508
{LogicalType::Time(true, LogicalType::TimeUnit::MILLIS),
15091509
"Time(isAdjustedToUTC=true, timeUnit=milliseconds)",
1510-
R"({"Type": "Time", "isAdjustedToUTC": true, "timeUnit": "milliseconds"})"},
1510+
R"({"Type":"Time","isAdjustedToUTC":true,"timeUnit":"milliseconds"})"},
15111511
{LogicalType::Time(true, LogicalType::TimeUnit::MICROS),
15121512
"Time(isAdjustedToUTC=true, timeUnit=microseconds)",
1513-
R"({"Type": "Time", "isAdjustedToUTC": true, "timeUnit": "microseconds"})"},
1513+
R"({"Type":"Time","isAdjustedToUTC":true,"timeUnit":"microseconds"})"},
15141514
{LogicalType::Time(true, LogicalType::TimeUnit::NANOS),
15151515
"Time(isAdjustedToUTC=true, timeUnit=nanoseconds)",
1516-
R"({"Type": "Time", "isAdjustedToUTC": true, "timeUnit": "nanoseconds"})"},
1516+
R"({"Type":"Time","isAdjustedToUTC":true,"timeUnit":"nanoseconds"})"},
15171517
{LogicalType::Time(false, LogicalType::TimeUnit::MILLIS),
15181518
"Time(isAdjustedToUTC=false, timeUnit=milliseconds)",
1519-
R"({"Type": "Time", "isAdjustedToUTC": false, "timeUnit": "milliseconds"})"},
1519+
R"({"Type":"Time","isAdjustedToUTC":false,"timeUnit":"milliseconds"})"},
15201520
{LogicalType::Time(false, LogicalType::TimeUnit::MICROS),
15211521
"Time(isAdjustedToUTC=false, timeUnit=microseconds)",
1522-
R"({"Type": "Time", "isAdjustedToUTC": false, "timeUnit": "microseconds"})"},
1522+
R"({"Type":"Time","isAdjustedToUTC":false,"timeUnit":"microseconds"})"},
15231523
{LogicalType::Time(false, LogicalType::TimeUnit::NANOS),
15241524
"Time(isAdjustedToUTC=false, timeUnit=nanoseconds)",
1525-
R"({"Type": "Time", "isAdjustedToUTC": false, "timeUnit": "nanoseconds"})"},
1525+
R"({"Type":"Time","isAdjustedToUTC":false,"timeUnit":"nanoseconds"})"},
15261526
{LogicalType::Timestamp(true, LogicalType::TimeUnit::MILLIS),
15271527
"Timestamp(isAdjustedToUTC=true, timeUnit=milliseconds, "
15281528
"is_from_converted_type=false, force_set_converted_type=false)",
1529-
R"({"Type": "Timestamp", "isAdjustedToUTC": true, "timeUnit": "milliseconds", )"
1530-
R"("is_from_converted_type": false, "force_set_converted_type": false})"},
1529+
R"({"Type":"Timestamp","isAdjustedToUTC":true,"timeUnit":"milliseconds",)"
1530+
R"("is_from_converted_type":false,"force_set_converted_type":false})"},
15311531
{LogicalType::Timestamp(true, LogicalType::TimeUnit::MICROS),
15321532
"Timestamp(isAdjustedToUTC=true, timeUnit=microseconds, "
15331533
"is_from_converted_type=false, force_set_converted_type=false)",
1534-
R"({"Type": "Timestamp", "isAdjustedToUTC": true, "timeUnit": "microseconds", )"
1535-
R"("is_from_converted_type": false, "force_set_converted_type": false})"},
1534+
R"({"Type":"Timestamp","isAdjustedToUTC":true,"timeUnit":"microseconds",)"
1535+
R"("is_from_converted_type":false,"force_set_converted_type":false})"},
15361536
{LogicalType::Timestamp(true, LogicalType::TimeUnit::NANOS),
15371537
"Timestamp(isAdjustedToUTC=true, timeUnit=nanoseconds, "
15381538
"is_from_converted_type=false, force_set_converted_type=false)",
1539-
R"({"Type": "Timestamp", "isAdjustedToUTC": true, "timeUnit": "nanoseconds", )"
1540-
R"("is_from_converted_type": false, "force_set_converted_type": false})"},
1539+
R"({"Type":"Timestamp","isAdjustedToUTC":true,"timeUnit":"nanoseconds",)"
1540+
R"("is_from_converted_type":false,"force_set_converted_type":false})"},
15411541
{LogicalType::Timestamp(false, LogicalType::TimeUnit::MILLIS, true, true),
15421542
"Timestamp(isAdjustedToUTC=false, timeUnit=milliseconds, "
15431543
"is_from_converted_type=true, force_set_converted_type=true)",
1544-
R"({"Type": "Timestamp", "isAdjustedToUTC": false, "timeUnit": "milliseconds", )"
1545-
R"("is_from_converted_type": true, "force_set_converted_type": true})"},
1544+
R"({"Type":"Timestamp","isAdjustedToUTC":false,"timeUnit":"milliseconds",)"
1545+
R"("is_from_converted_type":true,"force_set_converted_type":true})"},
15461546
{LogicalType::Timestamp(false, LogicalType::TimeUnit::MICROS),
15471547
"Timestamp(isAdjustedToUTC=false, timeUnit=microseconds, "
15481548
"is_from_converted_type=false, force_set_converted_type=false)",
1549-
R"({"Type": "Timestamp", "isAdjustedToUTC": false, "timeUnit": "microseconds", )"
1550-
R"("is_from_converted_type": false, "force_set_converted_type": false})"},
1549+
R"({"Type":"Timestamp","isAdjustedToUTC":false,"timeUnit":"microseconds",)"
1550+
R"("is_from_converted_type":false,"force_set_converted_type":false})"},
15511551
{LogicalType::Timestamp(false, LogicalType::TimeUnit::NANOS),
15521552
"Timestamp(isAdjustedToUTC=false, timeUnit=nanoseconds, "
15531553
"is_from_converted_type=false, force_set_converted_type=false)",
1554-
R"({"Type": "Timestamp", "isAdjustedToUTC": false, "timeUnit": "nanoseconds", )"
1555-
R"("is_from_converted_type": false, "force_set_converted_type": false})"},
1556-
{LogicalType::Interval(), "Interval", R"({"Type": "Interval"})"},
1554+
R"({"Type":"Timestamp","isAdjustedToUTC":false,"timeUnit":"nanoseconds",)"
1555+
R"("is_from_converted_type":false,"force_set_converted_type":false})"},
1556+
{LogicalType::Interval(), "Interval", R"({"Type":"Interval"})"},
15571557
{LogicalType::Int(8, false), "Int(bitWidth=8, isSigned=false)",
1558-
R"({"Type": "Int", "bitWidth": 8, "isSigned": false})"},
1558+
R"({"Type":"Int","bitWidth":8,"isSigned":false})"},
15591559
{LogicalType::Int(16, false), "Int(bitWidth=16, isSigned=false)",
1560-
R"({"Type": "Int", "bitWidth": 16, "isSigned": false})"},
1560+
R"({"Type":"Int","bitWidth":16,"isSigned":false})"},
15611561
{LogicalType::Int(32, false), "Int(bitWidth=32, isSigned=false)",
1562-
R"({"Type": "Int", "bitWidth": 32, "isSigned": false})"},
1562+
R"({"Type":"Int","bitWidth":32,"isSigned":false})"},
15631563
{LogicalType::Int(64, false), "Int(bitWidth=64, isSigned=false)",
1564-
R"({"Type": "Int", "bitWidth": 64, "isSigned": false})"},
1564+
R"({"Type":"Int","bitWidth":64,"isSigned":false})"},
15651565
{LogicalType::Int(8, true), "Int(bitWidth=8, isSigned=true)",
1566-
R"({"Type": "Int", "bitWidth": 8, "isSigned": true})"},
1566+
R"({"Type":"Int","bitWidth":8,"isSigned":true})"},
15671567
{LogicalType::Int(16, true), "Int(bitWidth=16, isSigned=true)",
1568-
R"({"Type": "Int", "bitWidth": 16, "isSigned": true})"},
1568+
R"({"Type":"Int","bitWidth":16,"isSigned":true})"},
15691569
{LogicalType::Int(32, true), "Int(bitWidth=32, isSigned=true)",
1570-
R"({"Type": "Int", "bitWidth": 32, "isSigned": true})"},
1570+
R"({"Type":"Int","bitWidth":32,"isSigned":true})"},
15711571
{LogicalType::Int(64, true), "Int(bitWidth=64, isSigned=true)",
1572-
R"({"Type": "Int", "bitWidth": 64, "isSigned": true})"},
1573-
{LogicalType::Null(), "Null", R"({"Type": "Null"})"},
1574-
{LogicalType::JSON(), "JSON", R"({"Type": "JSON"})"},
1575-
{LogicalType::BSON(), "BSON", R"({"Type": "BSON"})"},
1576-
{LogicalType::UUID(), "UUID", R"({"Type": "UUID"})"},
1577-
{LogicalType::Float16(), "Float16", R"({"Type": "Float16"})"},
1578-
{LogicalType::Geometry(), "Geometry(crs=)", R"({"Type": "Geometry"})"},
1572+
R"({"Type":"Int","bitWidth":64,"isSigned":true})"},
1573+
{LogicalType::Null(), "Null", R"({"Type":"Null"})"},
1574+
{LogicalType::JSON(), "JSON", R"({"Type":"JSON"})"},
1575+
{LogicalType::BSON(), "BSON", R"({"Type":"BSON"})"},
1576+
{LogicalType::UUID(), "UUID", R"({"Type":"UUID"})"},
1577+
{LogicalType::Float16(), "Float16", R"({"Type":"Float16"})"},
1578+
{LogicalType::Geometry(), "Geometry(crs=)", R"({"Type":"Geometry"})"},
15791579
{LogicalType::Geometry("srid:1234"), "Geometry(crs=srid:1234)",
1580-
R"({"Type": "Geometry", "crs": "srid:1234"})"},
1580+
R"({"Type":"Geometry","crs":"srid:1234"})"},
15811581
{LogicalType::Geometry(R"(crs with "quotes" and \backslashes\)"),
15821582
R"(Geometry(crs=crs with "quotes" and \backslashes\))",
1583-
R"({"Type": "Geometry", "crs": "crs with \"quotes\" and \\backslashes\\"})"},
1583+
R"({"Type":"Geometry","crs":"crs with \"quotes\" and \\backslashes\\"})"},
15841584
{LogicalType::Geometry("crs with control characters \u0001 and \u001f"),
15851585
"Geometry(crs=crs with control characters \u0001 and \u001f)",
1586-
R"({"Type": "Geometry", "crs": "crs with control characters \u0001 and \u001f"})"},
1586+
R"({"Type":"Geometry","crs":"crs with control characters \u0001 and \u001f"})"},
15871587
{LogicalType::Geography(), "Geography(crs=, algorithm=spherical)",
1588-
R"({"Type": "Geography"})"},
1588+
R"({"Type":"Geography"})"},
15891589
{LogicalType::Geography("srid:1234",
15901590
LogicalType::EdgeInterpolationAlgorithm::SPHERICAL),
15911591
"Geography(crs=srid:1234, algorithm=spherical)",
1592-
R"({"Type": "Geography", "crs": "srid:1234"})"},
1592+
R"({"Type":"Geography","crs":"srid:1234"})"},
15931593
{LogicalType::Geography("srid:1234",
15941594
LogicalType::EdgeInterpolationAlgorithm::VINCENTY),
15951595
"Geography(crs=srid:1234, algorithm=vincenty)",
1596-
R"({"Type": "Geography", "crs": "srid:1234", "algorithm": "vincenty"})"},
1596+
R"({"Type":"Geography","crs":"srid:1234","algorithm":"vincenty"})"},
15971597
{LogicalType::Geography("srid:1234",
15981598
LogicalType::EdgeInterpolationAlgorithm::THOMAS),
15991599
"Geography(crs=srid:1234, algorithm=thomas)",
1600-
R"({"Type": "Geography", "crs": "srid:1234", "algorithm": "thomas"})"},
1600+
R"({"Type":"Geography","crs":"srid:1234","algorithm":"thomas"})"},
16011601
{LogicalType::Geography("srid:1234",
16021602
LogicalType::EdgeInterpolationAlgorithm::ANDOYER),
16031603
"Geography(crs=srid:1234, algorithm=andoyer)",
1604-
R"({"Type": "Geography", "crs": "srid:1234", "algorithm": "andoyer"})"},
1604+
R"({"Type":"Geography","crs":"srid:1234","algorithm":"andoyer"})"},
16051605
{LogicalType::Geography("srid:1234",
16061606
LogicalType::EdgeInterpolationAlgorithm::KARNEY),
16071607
"Geography(crs=srid:1234, algorithm=karney)",
1608-
R"({"Type": "Geography", "crs": "srid:1234", "algorithm": "karney"})"},
1609-
{LogicalType::Variant(), "Variant(1)", R"({"Type": "Variant", "SpecVersion": 1})"},
1610-
{LogicalType::Variant(2), "Variant(2)", R"({"Type": "Variant", "SpecVersion": 2})"},
1611-
{LogicalType::None(), "None", R"({"Type": "None"})"},
1608+
R"({"Type":"Geography","crs":"srid:1234","algorithm":"karney"})"},
1609+
{LogicalType::Variant(), "Variant(1)", R"({"Type":"Variant","SpecVersion":1})"},
1610+
{LogicalType::Variant(2), "Variant(2)", R"({"Type":"Variant","SpecVersion":2})"},
1611+
{LogicalType::None(), "None", R"({"Type":"None"})"},
16121612
};
16131613

16141614
for (const ExpectedRepresentation& c : cases) {

0 commit comments

Comments
 (0)