Skip to content

Commit

Permalink
Merge pull request #50 from rustyconover/fix_yyjson_tag_comparisons
Browse files Browse the repository at this point in the history
Change yyjson_get_tag() to yyjson_get_type() when doing type comparisons.
  • Loading branch information
samansmink authored May 13, 2024
2 parents d89423c + 670f6ff commit 02171d5
Show file tree
Hide file tree
Showing 5 changed files with 12,165 additions and 8,384 deletions.
2 changes: 1 addition & 1 deletion src/common/iceberg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ IcebergSnapshot IcebergSnapshot::ParseSnapShot(yyjson_val *snapshot, idx_t icebe
vector<yyjson_val *> &schemas, string metadata_compression_codec,
bool skip_schema_inference) {
IcebergSnapshot ret;
auto snapshot_tag = yyjson_get_tag(snapshot);
auto snapshot_tag = yyjson_get_type(snapshot);
if (snapshot_tag != YYJSON_TYPE_OBJ) {
throw IOException("Invalid snapshot field found parsing iceberg metadata.json");
}
Expand Down
14 changes: 7 additions & 7 deletions src/common/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace duckdb {
static LogicalType ParseType(yyjson_val *type);

static LogicalType ParseStruct(yyjson_val *struct_type) {
D_ASSERT(yyjson_get_tag(struct_type) == YYJSON_TYPE_OBJ);
D_ASSERT(yyjson_get_type(struct_type) == YYJSON_TYPE_OBJ);
D_ASSERT(IcebergUtils::TryGetStrFromObject(struct_type, "type") == "struct");

child_list_t<LogicalType> children;
Expand All @@ -28,7 +28,7 @@ static LogicalType ParseStruct(yyjson_val *struct_type) {
}

static LogicalType ParseList(yyjson_val *list_type) {
D_ASSERT(yyjson_get_tag(list_type) == YYJSON_TYPE_OBJ);
D_ASSERT(yyjson_get_type(list_type) == YYJSON_TYPE_OBJ);
D_ASSERT(IcebergUtils::TryGetStrFromObject(list_type, "type") == "list");

// NOTE: 'element-id', 'element-required' are ignored for now
Expand All @@ -38,7 +38,7 @@ static LogicalType ParseList(yyjson_val *list_type) {
}

static LogicalType ParseMap(yyjson_val *map_type) {
D_ASSERT(yyjson_get_tag(map_type) == YYJSON_TYPE_OBJ);
D_ASSERT(yyjson_get_type(map_type) == YYJSON_TYPE_OBJ);
D_ASSERT(IcebergUtils::TryGetStrFromObject(map_type, "type") == "map");

// NOTE: 'key-id', 'value-id', 'value-required' are ignored for now
Expand All @@ -51,7 +51,7 @@ static LogicalType ParseMap(yyjson_val *map_type) {
}

static LogicalType ParseComplexType(yyjson_val *type) {
D_ASSERT(yyjson_get_tag(type) == YYJSON_TYPE_OBJ);
D_ASSERT(yyjson_get_type(type) == YYJSON_TYPE_OBJ);
auto type_str = IcebergUtils::TryGetStrFromObject(type, "type");

if (type_str == "struct") {
Expand All @@ -73,10 +73,10 @@ static LogicalType ParseType(yyjson_val *type) {
if (!val) {
throw IOException("Invalid field found while parsing field: type");
}
if (yyjson_get_tag(val) == YYJSON_TYPE_OBJ) {
if (yyjson_get_type(val) == YYJSON_TYPE_OBJ) {
return ParseComplexType(val);
}
if (yyjson_get_tag(val) != YYJSON_TYPE_STR) {
if (yyjson_get_type(val) != YYJSON_TYPE_STR) {
throw IOException("Invalid field found while parsing field: type");
}

Expand Down Expand Up @@ -154,7 +154,7 @@ static vector<IcebergColumnDefinition> ParseSchemaFromJson(yyjson_val *schema_js
if (type_str != "struct") {
throw IOException("Schema in JSON Metadata is invalid");
}
D_ASSERT(yyjson_get_tag(schema_json) == YYJSON_TYPE_OBJ);
D_ASSERT(yyjson_get_type(schema_json) == YYJSON_TYPE_OBJ);
D_ASSERT(IcebergUtils::TryGetStrFromObject(schema_json, "type") == "struct");
yyjson_val *field;
size_t max, idx;
Expand Down
6 changes: 3 additions & 3 deletions src/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ string IcebergUtils::GetFullPath(const string &iceberg_path, const string &relat

uint64_t IcebergUtils::TryGetNumFromObject(yyjson_val *obj, const string &field) {
auto val = yyjson_obj_getn(obj, field.c_str(), field.size());
if (!val || yyjson_get_tag(val) != YYJSON_TYPE_NUM) {
if (!val || yyjson_get_type(val) != YYJSON_TYPE_NUM) {
throw IOException("Invalid field found while parsing field: " + field);
}
return yyjson_get_uint(val);
}

bool IcebergUtils::TryGetBoolFromObject(yyjson_val *obj, const string &field) {
auto val = yyjson_obj_getn(obj, field.c_str(), field.size());
if (!val || yyjson_get_tag(val) != YYJSON_TYPE_BOOL) {
if (!val || yyjson_get_type(val) != YYJSON_TYPE_BOOL) {
throw IOException("Invalid field found while parsing field: " + field);
}
return yyjson_get_bool(val);
}

string IcebergUtils::TryGetStrFromObject(yyjson_val *obj, const string &field) {
auto val = yyjson_obj_getn(obj, field.c_str(), field.size());
if (!val || yyjson_get_tag(val) != YYJSON_TYPE_STR) {
if (!val || yyjson_get_type(val) != YYJSON_TYPE_STR) {
throw IOException("Invalid field found while parsing field: " + field);
}
return yyjson_get_str(val);
Expand Down
Loading

0 comments on commit 02171d5

Please sign in to comment.