[
https://issues.apache.org/jira/browse/AVRO-1902?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16694814#comment-16694814
]
ASF GitHub Bot commented on AVRO-1902:
--------------------------------------
dkulp closed pull request #158: AVRO-1902: C: Namespace "" means space = NULL.
URL: https://github.com/apache/avro/pull/158
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/lang/c/src/schema.c b/lang/c/src/schema.c
index 3ade1140e..a78f73314 100644
--- a/lang/c/src/schema.c
+++ b/lang/c/src/schema.c
@@ -935,6 +935,9 @@ avro_schema_from_json_t(json_t *json, avro_schema_t *schema,
avro_str_free(namespace);
} else if (json_is_string(json_namespace)) {
const char *namespace =
json_string_value(json_namespace);
+ if (strlen(namespace) == 0) {
+ namespace = NULL;
+ }
*schema = avro_schema_record(fullname,
namespace);
} else {
*schema = avro_schema_record(fullname,
parent_namespace);
@@ -1032,6 +1035,9 @@ avro_schema_from_json_t(json_t *json, avro_schema_t
*schema,
avro_str_free(namespace);
} else if (json_is_string(json_namespace)) {
const char *namespace =
json_string_value(json_namespace);
+ if (strlen(namespace) == 0) {
+ namespace = NULL;
+ }
*schema = avro_schema_enum_ns(fullname,
namespace);
} else {
*schema = avro_schema_enum_ns(fullname,
parent_namespace);
@@ -1166,6 +1172,9 @@ avro_schema_from_json_t(json_t *json, avro_schema_t
*schema,
avro_str_free(namespace);
} else if (json_is_string(json_namespace)) {
const char *namespace =
json_string_value(json_namespace);
+ if (strlen(namespace) == 0) {
+ namespace = NULL;
+ }
*schema = avro_schema_fixed_ns(fullname,
namespace, (int64_t) size);
} else {
*schema = avro_schema_fixed_ns(fullname,
parent_namespace, (int64_t) size);
@@ -1638,9 +1647,11 @@ static int write_record(avro_writer_t out, const struct
avro_record_schema_t *re
check(rval, avro_write_str(out, "{\"type\":\"record\",\"name\":\""));
check(rval, avro_write_str(out, record->name));
check(rval, avro_write_str(out, "\","));
- if (record->space && nullstrcmp(record->space, parent_namespace)) {
+ if (nullstrcmp(record->space, parent_namespace)) {
check(rval, avro_write_str(out, "\"namespace\":\""));
- check(rval, avro_write_str(out, record->space));
+ if (record->space) {
+ check(rval, avro_write_str(out, record->space));
+ }
check(rval, avro_write_str(out, "\","));
}
check(rval, avro_write_str(out, "\"fields\":["));
@@ -1666,9 +1677,11 @@ static int write_enum(avro_writer_t out, const struct
avro_enum_schema_t *enump,
check(rval, avro_write_str(out, "{\"type\":\"enum\",\"name\":\""));
check(rval, avro_write_str(out, enump->name));
check(rval, avro_write_str(out, "\","));
- if (enump->space && nullstrcmp(enump->space, parent_namespace)) {
+ if (nullstrcmp(enump->space, parent_namespace)) {
check(rval, avro_write_str(out, "\"namespace\":\""));
- check(rval, avro_write_str(out, enump->space));
+ if (enump->space) {
+ check(rval, avro_write_str(out, enump->space));
+ }
check(rval, avro_write_str(out, "\","));
}
check(rval, avro_write_str(out, "\"symbols\":["));
@@ -1697,9 +1710,11 @@ static int write_fixed(avro_writer_t out, const struct
avro_fixed_schema_t *fixe
check(rval, avro_write_str(out, "{\"type\":\"fixed\",\"name\":\""));
check(rval, avro_write_str(out, fixed->name));
check(rval, avro_write_str(out, "\","));
- if (fixed->space && nullstrcmp(fixed->space, parent_namespace)) {
+ if (nullstrcmp(fixed->space, parent_namespace)) {
check(rval, avro_write_str(out, "\"namespace\":\""));
- check(rval, avro_write_str(out, fixed->space));
+ if (fixed->space) {
+ check(rval, avro_write_str(out, fixed->space));
+ }
check(rval, avro_write_str(out, "\","));
}
check(rval, avro_write_str(out, "\"size\":"));
diff --git a/lang/c/tests/schema_tests/pass/namespace_null_enum
b/lang/c/tests/schema_tests/pass/namespace_null_enum
new file mode 100644
index 000000000..3c3a74528
--- /dev/null
+++ b/lang/c/tests/schema_tests/pass/namespace_null_enum
@@ -0,0 +1,8 @@
+{"type": "record", "name": "R", "fields": [
+ {"name": "s", "type": {"type": "record", "namespace": "x", "name": "Y",
"fields": [
+ {"name": "e", "type": {"type": "enum", "namespace": "", "name": "Z",
+ "symbols": ["Foo", "Bar"]}
+ }
+ ]}},
+ {"name": "t", "type": "Z"}
+]}
diff --git a/lang/c/tests/schema_tests/pass/namespace_null_fixed
b/lang/c/tests/schema_tests/pass/namespace_null_fixed
new file mode 100644
index 000000000..a3aa5701f
--- /dev/null
+++ b/lang/c/tests/schema_tests/pass/namespace_null_fixed
@@ -0,0 +1,7 @@
+{"type": "record", "name": "R", "fields": [
+ {"name": "s", "type": {"type": "record", "namespace": "x", "name": "Y",
"fields": [
+ {"name": "e", "type": {"type": "fixed", "namespace": "", "name": "Z",
"size": 8}
+ }
+ ]}},
+ {"name": "t", "type": "Z"}
+]}
diff --git a/lang/c/tests/schema_tests/pass/namespace_null_record
b/lang/c/tests/schema_tests/pass/namespace_null_record
new file mode 100644
index 000000000..4b18dd54b
--- /dev/null
+++ b/lang/c/tests/schema_tests/pass/namespace_null_record
@@ -0,0 +1,8 @@
+{"type": "record", "name": "R", "fields": [
+ {"name": "s", "type": {"type": "record", "namespace": "x", "name": "Y",
"fields": [
+ {"name": "e", "type": {"type": "record", "namespace": "", "name": "Z",
"fields": [
+ {"name": "f", "type": "Z"}
+ ]}}
+ ]}},
+ {"name": "t", "type": "Z"}
+]}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> C: namespace "" should mean namespace = NULL
> --------------------------------------------
>
> Key: AVRO-1902
> URL: https://issues.apache.org/jira/browse/AVRO-1902
> Project: Apache Avro
> Issue Type: Bug
> Components: c
> Reporter: Ben Walsh
> Priority: Minor
> Attachments: AVRO-1902.patch
>
>
> Similar to AVRO-1295 but for the C library. Namespace "" should be the NULL
> namespace when the schema is parsed. For example this breaks:
> ```
> {"type": "record", "name": "R", "fields": [
> {"name": "s", "type": {"type": "record", "namespace": "x", "name": "Y",
> "fields": [
> {"name": "e", "type": {"type": "record", "namespace": "", "name": "Z",
> "fields": [
> {"name": "f", "type": "Z"}
> ]}}
> ]}},
> {"name": "t", "type": "Z"}
> ]}
> ```
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)