[
https://issues.apache.org/jira/browse/AVRO-1778?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15356510#comment-15356510
]
Chunfy.Tseng commented on AVRO-1778:
------------------------------------
protocol:BigDataService.avpr
{
"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" ]
}, {
"name" : "ts",
"type" : [ "null", "string" ]
} ]
}, {
"type" : "record",
"name" : "QueryORSaveArgs",
"namespace" : "com.hbs.avro.dto",
"fields" : [ {
"name" : "rowKey",
"type" : "string"
}, {
"name" : "families",
"type" : {
"type" : "array",
"items" : {
"type" : "record",
"name" : "ColumnFamily",
"fields" : [ {
"name" : "name",
"type" : "string"
}, {
"name" : "kvts",
"type" : [ "null", {
"type" : "array",
"items" : "KVTS"
} ]
} ]
}
}
} ]
}, {
"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" : "record",
"name" : "FilterType",
"namespace" : "com.hbs.avro.dto",
"fields" : [ {
"name" : "rowFilterType",
"type" : [ "null", {
"type" : "record",
"name" : "RowKeyFilter",
"fields" : [ {
"name" : "byteArrayComparable",
"type" : "ByteArrayComparable"
}, {
"name" : "compareOp",
"type" : "CompareOp"
} ]
}, {
"type" : "record",
"name" : "RowKeyScanFilter",
"fields" : [ {
"name" : "startRow",
"type" : "string"
}, {
"name" : "stopRow",
"type" : "string"
} ]
}, {
"type" : "record",
"name" : "FirstKeyOnlyFilter",
"fields" : [ {
"name" : "firstKeyOnlyFilter",
"type" : "boolean"
} ]
} ]
}, {
"name" : "familyFilterType",
"type" : [ "null", {
"type" : "record",
"name" : "FamilyFilter",
"fields" : [ {
"name" : "byteArrayComparable",
"type" : "ByteArrayComparable"
}, {
"name" : "compareOp",
"type" : "CompareOp"
} ]
} ]
}, {
"name" : "columnFilterType",
"type" : [ "null", {
"type" : "record",
"name" : "ColumnRangeFilter",
"fields" : [ {
"name" : "minColumn",
"type" : "string"
}, {
"name" : "minColumnInclusive",
"type" : "boolean"
}, {
"name" : "maxColumn",
"type" : "string"
}, {
"name" : "maxColumnInclusive",
"type" : "boolean"
} ]
}, {
"type" : "record",
"name" : "QualifierFilter",
"fields" : [ {
"name" : "byteArrayComparable",
"type" : "ByteArrayComparable"
}, {
"name" : "compareOp",
"type" : "CompareOp"
} ]
} ]
}, {
"name" : "columnValueFilterType",
"type" : [ "null", {
"type" : "record",
"name" : "ColumnValueFilter",
"fields" : [ {
"name" : "byteArrayComparable",
"type" : "ByteArrayComparable"
}, {
"name" : "compareOp",
"type" : "CompareOp"
} ]
} ]
}, {
"name" : "pageFilterType",
"type" : [ "null", {
"type" : "record",
"name" : "PageFilter",
"fields" : [ {
"name" : "pageSize",
"type" : "int"
} ]
} ]
} ]
} ],
"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"
}
}
}
client.js
var avro = require("D:\\Soft\\nodejs\\node_modules\\avsc");
//var avro = require("D:\\Soft\\nodejs\\node_modules\\avro-js"),
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:"tz_ns",
queryORSaveArgses : [
{
rowKey : "c0f68aed-64c0-4cd1-9be0-49ec61f950c4_rk_tz",
families : [
{
name:"cf1"
},
{
name:"cf2"
}
]
}
]
}, ee, function(err, res) {
console.log("err:" + err);
console.log("res:" + res);
ee.destroy();
});
print:
err: Error: invalid request: invalid ["null","string"]: "tz_ns"
res: undefined
In Java and python can pass, but can not in js, please help me to see where is
the problem? Thank you very much!
> IPC/RPC for JavaScript
> ----------------------
>
> Key: AVRO-1778
> URL: https://issues.apache.org/jira/browse/AVRO-1778
> Project: Avro
> Issue Type: Improvement
> Components: javascript
> Reporter: Matthieu Monsch
> Assignee: Ryan Blue
> Attachments: AVRO-1778.patch
>
>
> This patch adds protocols to the JavaScript implementation.
> The API was designed to:
> + Be simple and idiomatic. The `Protocol` class added here is heavily
> inspired by node.js' core `EventEmitter` to keep things as familiar as
> possible [1]. Getting a client and server working is straightforward and
> requires very few lines of code [2].
> + Support arbitrary transports, both stateful and stateless. Built-in node.js
> streams are supported out of the box (e.g. TCP/UNIX sockets, or even
> stdin/stdout). Exchanging messages over a custom transport requires
> implementing a single simple function (see [3] for an example).
> + Work both server-side and in the browser!
> Ps: I also tested against both the Java and Python implementations over HTTP
> and communication worked.
> [1] https://github.com/mtth/avsc/wiki/API#ipc--rpc
> [2] https://github.com/mtth/avsc/wiki/Advanced-usage#remote-procedure-calls
> [3] https://github.com/mtth/avsc/wiki/Advanced-usage#transient-streams
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)