Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change yyjson_get_tag() to yyjson_get_type() when doing type comparisons. #50

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading