[
https://issues.apache.org/jira/browse/AVRO-3403?focusedWorklogId=747712&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-747712
]
ASF GitHub Bot logged work on AVRO-3403:
----------------------------------------
Author: ASF GitHub Bot
Created on: 25/Mar/22 10:30
Start Date: 25/Mar/22 10:30
Worklog Time Spent: 10m
Work Description: opwvhk commented on a change in pull request #1588:
URL: https://github.com/apache/avro/pull/1588#discussion_r835143321
##########
File path: lang/java/idl/src/main/java/org/apache/avro/idl/Schemas.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+package org.apache.avro.idl;
+
+import org.apache.avro.Schema;
+import org.apache.avro.Schema.Field;
+
+import java.util.ArrayDeque;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.IdentityHashMap;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+/**
+ * Avro Schema utilities, to traverse...
+ */
+public final class Schemas {
+
+ private Schemas() {
+ }
+
+ /**
+ * Depth first visit.
+ */
+ public static <T> T visit(final Schema start, final SchemaVisitor<T>
visitor) {
+ // Set of Visited Schemas
+ IdentityHashMap<Schema, Schema> visited = new IdentityHashMap<>();
+ // Stack that contains the Schemas to process and afterVisitNonTerminal
+ // functions.
+ // Deque<Either<Schema, Supplier<SchemaVisitorAction>>>
+ // Using Either<...> has a cost we want to avoid...
+ Deque<Object> dq = new ArrayDeque<>();
+ dq.push(start);
+ Object current;
+ while ((current = dq.poll()) != null) {
+ if (current instanceof Supplier) {
+ // We are executing a non-terminal post visit.
+ @SuppressWarnings("unchecked")
+ SchemaVisitorAction action = ((Supplier<SchemaVisitorAction>)
current).get();
+ switch (action) {
+ case CONTINUE:
+ break;
+ case SKIP_SUBTREE:
+ throw new UnsupportedOperationException();
Review comment:
Yeah, I'll add one. This was copied from the `avro-compiler` module
(there will be still 26 cases of this exception without a message left).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 747712)
Time Spent: 40m (was: 0.5h)
> Migrate from JavaCC to ANTLR
> ----------------------------
>
> Key: AVRO-3403
> URL: https://issues.apache.org/jira/browse/AVRO-3403
> Project: Apache Avro
> Issue Type: Improvement
> Components: build, dependencies, java, tools
> Reporter: Oscar Westra van Holthe - Kind
> Assignee: Oscar Westra van Holthe - Kind
> Priority: Major
> Labels: pull-request-available
> Time Spent: 40m
> Remaining Estimate: 0h
>
> Although JavaCC has been updated recently, there are quite some forks and
> development is quite erratic. The best maintained fork also has no presence
> in Maven Central yet. Worse (IMHO), it's Java only. This limits the use of
> the IDL format to Java and the Avro tools.
> As proposed on the mailling list last January, in the thread [Maintaining the
> IDL in the 21st
> century|https://lists.apache.org/thread/7c99hkkl59l78x5kyf7bd80cnyd1do3j],
> this improvement issue is to migrate the code to ANTLR.
> Related changes:
> # Place the ANTLR grammar in a subdirectory in the toplevel {{share}}
> directory, so it can be reused for other languages than Java (note: the
> Grammar may not contain any actions/code).
> # Ensure the IDL parsing API allows extending the IDL syntax to an {{.avsc}}
> equivalent.
> # Add a new {{java/idl}} module with the new parser. Make it a dependency of
> the {{java/compiler}} module and use it instead of the old parser.
> Bonus: this allows us to (also) create a parser that yields a single protocol
> (at first) or schema (future change).
> # Keep the old parser in the {{java/compiler}} module for backwards
> compatibility, mark it as deprecated and document its removal in a future
> version.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)