[
https://issues.apache.org/jira/browse/AVRO-1872?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15358381#comment-15358381
]
Chunfy.Tseng commented on AVRO-1872:
------------------------------------
"Protocol" file content is as follows:
{code}
{
"protocol": "BigDataService",
"namespace": "com.hbs.service",
"types": [
{
"type": "record",
"name": "Status",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "code",
"type": "int"
},
{
"name": "error",
"type": [
"null",
"string"
]
}
]
},
{
"type": "record",
"name": "KVTS",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "key",
"type": "string"
},
{
"name": "val",
"type": [
"null",
"string",
"bytes"
]
},
{
"name": "ts",
"type": [
"null",
"string"
]
}
]
},
{
"type": "record",
"name": "ColumnFamily",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "kvts",
"type": [
"null",
{
"type": "array",
"items": "KVTS"
}
]
}
]
},
{
"type": "record",
"name": "QueryORSaveArgs",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "rowKey",
"type": "string"
},
{
"name": "families",
"type": {
"type": "array",
"items": "ColumnFamily"
}
}
]
},
{
"type": "record",
"name": "QueryResponse",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "table",
"type": "string"
},
{
"name": "nameSpace",
"type": [
"null",
"string"
]
},
{
"name": "result",
"type": [
"null",
{
"type": "array",
"items": "QueryORSaveArgs"
}
]
},
{
"name": "status",
"type": "Status"
}
]
},
{
"type": "enum",
"name": "ByteArrayComparable",
"namespace": "com.hbs.avro.dto",
"doc": "the filter support comparator",
"symbols": [
"BinaryComparator",
"BinaryPrefixComparator",
"SubstringComparator",
"RegexStringComparator"
]
},
{
"type": "enum",
"name": "CompareOp",
"namespace": "com.hbs.avro.dto",
"doc": "the comparator support more symbols",
"symbols": [
"LESS",
"LESS_OR_EQUAL",
"EQUAL",
"NOT_EQUAL",
"GREATER_OR_EQUAL",
"GREATER"
]
},
{
"type": "enum",
"name": "Operator",
"namespace": "com.hbs.avro.dto",
"symbols": [
"AND",
"OR"
]
},
{
"type": "record",
"name": "RowKeyFilter",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "byteArrayComparable",
"type": "ByteArrayComparable"
},
{
"name": "compareOp",
"type": "CompareOp"
}
]
},
{
"type": "record",
"name": "RowKeyScanFilter",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "startRow",
"type": "string"
},
{
"name": "stopRow",
"type": "string"
}
]
},
{
"type": "record",
"name": "FirstKeyOnlyFilter",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "firstKeyOnlyFilter",
"type": "boolean"
}
]
},
{
"type": "record",
"name": "FamilyFilter",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "byteArrayComparable",
"type": "ByteArrayComparable"
},
{
"name": "compareOp",
"type": "CompareOp"
}
]
},
{
"type": "record",
"name": "ColumnRangeFilter",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "minColumn",
"type": "string"
},
{
"name": "minColumnInclusive",
"type": "boolean"
},
{
"name": "maxColumn",
"type": "string"
},
{
"name": "maxColumnInclusive",
"type": "boolean"
}
]
},
{
"type": "record",
"name": "QualifierFilter",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "byteArrayComparable",
"type": "ByteArrayComparable"
},
{
"name": "compareOp",
"type": "CompareOp"
}
]
},
{
"type": "record",
"name": "ColumnValueFilter",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "byteArrayComparable",
"type": "ByteArrayComparable"
},
{
"name": "compareOp",
"type": "CompareOp"
}
]
},
{
"type": "record",
"name": "PageFilter",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "pageSize",
"type": "int"
}
]
},
{
"type": "record",
"name": "FilterType",
"namespace": "com.hbs.avro.dto",
"fields": [
{
"name": "operator",
"type": "Operator"
},
{
"name": "rowFilterType",
"type": [
"null",
"RowKeyFilter",
"RowKeyScanFilter",
"FirstKeyOnlyFilter"
]
},
{
"name": "familyFilterType",
"type": [
"null",
"FamilyFilter"
]
},
{
"name": "columnFilterType",
"type": [
"null",
"ColumnRangeFilter",
"QualifierFilter"
]
},
{
"name": "columnValueFilterType",
"type": [
"null",
"ColumnValueFilter"
]
},
{
"name": "pageFilterType",
"type": [
"null",
"PageFilter"
]
}
]
}
],
"messages": {
"query": {
"request": [
{
"name": "table",
"type": "string"
},
{
"name": "nameSpace",
"type": [
"null",
"string"
]
},
{
"name": "queryORSaveArgses",
"type": {
"type": "array",
"items": "com.hbs.avro.dto.QueryORSaveArgs"
}
},
{
"name": "filterType",
"type": [
"null",
"com.hbs.avro.dto.FilterType"
]
}
],
"response": "com.hbs.avro.dto.QueryResponse"
},
"save": {
"request": [
{
"name": "table",
"type": "string"
},
{
"name": "nameSpace",
"type": [
"null",
"string"
]
},
{
"name": "queryORSaveArgses",
"type": {
"type": "array",
"items": "com.hbs.avro.dto.QueryORSaveArgs"
}
}
],
"response": "com.hbs.avro.dto.Status"
}
}
}
{code}
Client.Js file contents as follows:
{code}
'use strict';
var avro = require("D:\\Soft\\nodejs\\node_modules\\avsc");
//var avro = require("D:\\Soft\\nodejs\\node_modules\\avro-js"),
var net = require('net');
var protocol =
avro.parse('D:/workspace-mars2/HbaseClient/src/main/resource/avro/BigDataService.avpr',{wrapUnions:
true});
var socket = net.createConnection({
host : 'localhost',
port : 9966
});
var ee = protocol.createEmitter(socket).on('eot', function() {
socket.destroy();
});
protocol.emit('query', {
"table":"tz_tbl",
"nameSpace":{
"string":"tz_ns"
},
"queryORSaveArgses" : [
{
"rowKey" : "c0f68aed-64c0-4cd1-9be0-49ec61f950c4_rk_tz",
"families": [
{
"name":"cf1",
"kvts":null
},
{
"name":"cf2",
"kvts":null
}
]
}
],
"filterType":null
}, ee, function(err, res) {
console.log("err:" + err);
console.log("res:" + res);
ee.destroy();
});
{code}
Error message is as follows:
{code}
err:Error: interrupted
res:undefined
events.js:141
throw er; // Unhandled 'error' event
^
Error: handshake error: ambiguous unwrapped union:
[
"null",
{
"name": "com.hbs.avro.dto.RowKeyFilter",
"type": "record",
"fields": [
{
"name": "byteArrayComparable",
"type": {
"name": "com.hbs.avro.dto.ByteArrayComparable",
"type": "enum",
"symbols": [
"BinaryComparator",
"BinaryPrefixComparator",
"SubstringComparator",
"RegexStringComparator"
],
"aliases": []
},
"order": "ascending",
"aliases": []
},
{
"name": "compareOp",
"type": {
"name": "com.hbs.avro.dto.CompareOp",
"type": "enum",
"symbols": [
"LESS",
"LESS_OR_EQUAL",
"EQUAL",
"NOT_EQUAL",
"GREATER_OR_EQUAL",
"GREATER"
],
"aliases": []
},
"order": "ascending",
"aliases": []
}
],
"aliases": []
},
{
"name": "com.hbs.avro.dto.RowKeyScanFilter",
"type": "record",
"fields": [
{
"name": "startRow",
"type": "string",
"order": "ascending",
"aliases": []
},
{
"name": "stopRow",
"type": "string",
"order": "ascending",
"aliases": []
}
],
"aliases": []
},
{
"name": "com.hbs.avro.dto.FirstKeyOnlyFilter",
"type": "record",
"fields": [
{
"name": "firstKeyOnlyFilter",
"type": "boolean",
"order": "ascending",
"aliases": []
}
],
"aliases": []
}
]
at wrapError (D:\Soft\nodejs\node_modules\avsc\lib\protocols.js:1400:13)
at NettyDecoder.onPing
(D:\Soft\nodejs\node_modules\avsc\lib\protocols.js:622:26)
at emitOne (events.js:77:13)
at NettyDecoder.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at NettyDecoder.Readable.push (_stream_readable.js:110:10)
at NettyDecoder.Transform.push (_stream_transform.js:128:32)
at NettyDecoder._transform
(D:\Soft\nodejs\node_modules\avsc\lib\protocols.js:1317:12)
at NettyDecoder.Transform._read (_stream_transform.js:167:10)
at NettyDecoder.Transform._write (_stream_transform.js:155:12)
{code}
I read the https://avro.apache.org/docs/1.8.0/spec.html#json_encoding still
don't know where is wrong, Java and python can pass but the js is not.
Could you tell me how to request the client(js) to is correct?
> Using union in nodejs, when has several different names in the union's record
> will report the Error at this time: ambiguous unwrapped the union, but the
> same protocol in Java: no problem
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: AVRO-1872
> URL: https://issues.apache.org/jira/browse/AVRO-1872
> Project: Avro
> Issue Type: Bug
> Components: java, javascript, js
> Affects Versions: 1.8.1
> Environment: node.js
> Reporter: Chunfy.Tseng
> Assignee: Matthieu Monsch
>
> protocol eg:
> {
> "protocol": "Test",
> "namespace": "test.avro",
> "types": [
> {
> "type": "record",
> "name": "AAA",
> "fields": [
> {
> "name": "a",
> "type": "string"
> }
> ]
> },
> {
> "type": "record",
> "name": "BBB",
> "fields": [
> {
> "name": "b",
> "type": "string"
> },
> {
> "name": "a",
> "type": "AAA"
> }
> ]
> },
> {
> "type": "record",
> "name": "CCC",
> "fields": [
> {
> "name": "c",
> "type": "string"
> },
> {
> "name": "t",
> "type": "int"
> }
> ]
> },
> {
> "type": "record",
> "name": "DDD",
> "fields": [
> {
> "name": "temp",
> "type": "string"
> },
> {
> "name": "d",
> "type": [
> "null",
> "BBB",
> "CCC"
> ]
> }
> ]
> }
> ],
> "messages": {}
> }
> in java use cmd:java -jar D:\workspace-mars2\Avro\lib\avro-tools-1.8.1.jar
> compile protocol D:\new\Test.avpr D:\new is ok.
> but in node.js code:
> var avro = require("D:\\Soft\\nodejs\\node_modules\\avsc");
> var protocol = avro.parse("./Test.avpr");
> Prompt error message as below:
> D:\Soft\nodejs\node_modules\avsc\lib\types.js:918
> throw new Error(f('ambiguous unwrapped union: %j', this));
> Error: ambiguous unwrapped
> union:["null",{"name":"test.avro.BBB","type":"record","fields":[{"name":"b","type":"string","order":"ascending","aliases":[]},{"name":"a","type":{"name":"test.avro.AAA","type":"record","fields":[{"name":"a","type":"string","order":"ascending","aliases":[]}],"aliases":[]},"order":"ascending","aliases":[]}],"aliases":[]},{"name":"test.avro.CCC","type":"record","fields":[{"name":"c","type":"string","order":"ascending","aliases":[]},{"name":"t","type":"int","order":"ascending","aliases":[]}],"aliases":[]}]
> it is bug?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)