This is an automated email from the ASF dual-hosted git repository.
rskraba pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new 603319f AVRO-2925: add support for UUID in compiler (#951)
603319f is described below
commit 603319f79ca7db6a3b9f40e5270aa8f137d0fb25
Author: xaneesaxo <[email protected]>
AuthorDate: Fri Sep 11 14:00:21 2020 +0530
AVRO-2925: add support for UUID in compiler (#951)
* AVRO-2925: add support for UUID in compiler
* add license
* fix formatting with doc
---
.../javacc/org/apache/avro/compiler/idl/idl.jj | 18 +++++-----
lang/java/compiler/src/test/idl/input/uuid.avdl | 41 ++++++++++++++++++++++
lang/java/compiler/src/test/idl/output/uuid.avpr | 25 +++++++++++++
3 files changed, 76 insertions(+), 8 deletions(-)
diff --git
a/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
b/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
index a7053a4..7787b45 100644
--- a/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
+++ b/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
@@ -243,6 +243,7 @@ TOKEN :
| < TIMESTAMP: "timestamp_ms" >
| < DECIMAL: "decimal" >
| < LOCAL_TIMESTAMP: "local_timestamp_ms" >
+| < UUID: "uuid" >
}
/* LITERALS */
@@ -254,7 +255,7 @@ TOKEN :
( <DECIMAL_LITERAL> (["l","L"])?
| <HEX_LITERAL> (["l","L"])?
| <OCTAL_LITERAL> (["l","L"])?
- )
+ )
>
|
< #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
@@ -1180,7 +1181,7 @@ Protocol ImportIdl() : {
<IDL> importFile = JsonString() ";"
{
try {
- Idl idl = new Idl(findFile(importFile), this);
+ Idl idl = new Idl(findFile(importFile), this);
try {
return idl.CompilationUnit();
} finally {
@@ -1188,7 +1189,7 @@ Protocol ImportIdl() : {
}
} catch (IOException e) {
throw error("Error importing "+importFile+": "+e, token);
- }
+ }
}
}
@@ -1208,7 +1209,7 @@ Protocol ImportProtocol() : {
}
} catch (IOException e) {
throw error("Error importing "+importFile+": "+e, token);
- }
+ }
}
}
@@ -1231,7 +1232,7 @@ Schema ImportSchema() : {
}
} catch (IOException e) {
throw error("Error importing "+importFile+": "+e, token);
- }
+ }
}
}
@@ -1319,11 +1320,11 @@ void VariableDeclarator(Schema type, List<Field>
fields):
}
{
( SchemaProperty(props) )*
-
+
name = Identifier()
[ <EQUALS> defaultValue=Json() ]
-
+
{
Field.Order order = Field.Order.ASCENDING;
for (String key : props.keySet())
@@ -1378,7 +1379,7 @@ private Message MessageDeclaration(Protocol p,
Map<String, JsonNode> props):
return oneWay
? p.createMessage(name, msgDoc, props, request)
: p.createMessage(name, msgDoc, props, request, response, errors);
-
+
}
}
@@ -1500,6 +1501,7 @@ Schema PrimitiveType():
| "timestamp_ms" { return
LogicalTypes.timestampMillis().addToSchema(Schema.create(Type.LONG)); }
| "local_timestamp_ms" { return
LogicalTypes.localTimestampMillis().addToSchema(Schema.create(Type.LONG)); }
| "decimal" { return DecimalTypeProperties(); }
+| "uuid" {return LogicalTypes.uuid().addToSchema(Schema.create(Type.STRING));}
}
Schema DecimalTypeProperties():
diff --git a/lang/java/compiler/src/test/idl/input/uuid.avdl
b/lang/java/compiler/src/test/idl/input/uuid.avdl
new file mode 100644
index 0000000..f0e1ac8
--- /dev/null
+++ b/lang/java/compiler/src/test/idl/input/uuid.avdl
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
+/**
+Testing UUID fields
+*/
+
+@namespace("org.apache.avro")
+protocol MyProtocol {
+ record APlaygroundEvent {
+
+ /**
+ * Documentation must be provided for each attribute
+ */
+ uuid identifier;
+
+
+ /**
+ * a nullable uuid field
+ */
+
+ union { null, uuid } optionalString;
+ }
+}
diff --git a/lang/java/compiler/src/test/idl/output/uuid.avpr
b/lang/java/compiler/src/test/idl/output/uuid.avpr
new file mode 100644
index 0000000..cffdba8
--- /dev/null
+++ b/lang/java/compiler/src/test/idl/output/uuid.avpr
@@ -0,0 +1,25 @@
+{
+ "protocol" : "MyProtocol",
+ "namespace" : "org.apache.avro",
+ "doc" : "Testing UUID fields",
+ "types" : [ {
+ "type" : "record",
+ "name" : "APlaygroundEvent",
+ "fields" : [ {
+ "name" : "identifier",
+ "type" : {
+ "type" : "string",
+ "logicalType" : "uuid"
+ },
+ "doc" : "* Documentation must be provided for each attribute"
+ }, {
+ "name" : "optionalString",
+ "type" : [ "null", {
+ "type" : "string",
+ "logicalType" : "uuid"
+ } ],
+ "doc" : "* a nullable uuid field"
+ } ]
+ } ],
+ "messages" : { }
+}