[ 
https://issues.apache.org/jira/browse/TINKERPOP-2234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18019824#comment-18019824
 ] 

ASF GitHub Bot commented on TINKERPOP-2234:
-------------------------------------------

spmallette commented on code in PR #3207:
URL: https://github.com/apache/tinkerpop/pull/3207#discussion_r2343906961


##########
docs/src/dev/future/proposal-type-predicate-8.asciidoc:
##########
@@ -0,0 +1,264 @@
+////
+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
+
+  http://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.
+////
+
+image::apache-tinkerpop-logo.png[width=500,link="https://tinkerpop.apache.org";]
+
+*x.y.z - Proposal 8*
+
+== Type Predicate
+
+=== Motivation
+
+Following up on 
link:https://issues.apache.org/jira/browse/TINKERPOP-2234[TINKERPOP-2234], 
filtering of traversers based on types would be a very convenient addition to 
data manipulation in Gremlin. For example, when we perform union of traversals 
and only want vertices or edges, currently there is no simple way to assert the 
type and pass it through.
+
+=== Type Token Definition & Implementation
+
+To facilitate type assertion across GLVs, using a unified set of enum tokens 
is the most convenient, especially given we do not want to leak Java types into 
other languages. The proposal here is to use a defined set of Gremlin Type 
tokens (see Appendix), and use an interface structure to allow providers to 
implement and register their own type tokens to be used with the Gremlin 
Language.
+
+==== Gremlin Type Enum
+
+We will define a `GType` enum consiste of core types in Gremlin be used with 
the type predicate (for full set of types, see Appendix), for type safety and 
maintainability across GLVs. This will also be the singel set of type enum used 
in Gremlin steps (e.g. replacing `N` in `asNumber()`).
+
+This enum itself will not be extensable, however it will contain a GlobalCache 
which providers can use to register their own types with the Grammar to be used 
as string arguments.
+
+[source,java]
+----
+public enum GType {
+  BYTE(Byte.class),
+  DOUBLE(Double.class),
+  FLOAT(Float.class),
+  INT(Integer.class),
+  LIST(List.class),
+  LONG(Long.class),
+  MAP(Map.class),
+  NULL(OffsetDateTime.class),;
+
+  private final Class<?> javaType;
+
+  GType(Class<?> javaType) {
+    this.javaType = javaType;
+  }
+
+  public Class<?> getType() { return javaType; }
+
+  public GType fromName(String name) { return 
GType.valueOf(name.toUpperCase()); }
+
+  static final class GlobalTypeCache {
+
+      private GlobalTypeCache() {
+          throw new IllegalStateException("Utility class");
+      }
+
+      private static final Map<String, Class<?>> GLOBAL_TYPE_REGISTRY = new 
ConcurrentHashMap<>() {
+      };
+    }
+}
+----
+
+=== Addition of `P.typeOf(token)`

Review Comment:
   I guess this is implemented like `Text` enum. Wouldn't it be 
`PBiPredicate<Object, GType>`? I assume the various `P.typeOf()` overloads 
would normalize to a `GType` or is that not how it would work?





> Introduce Type Predicate
> ------------------------
>
>                 Key: TINKERPOP-2234
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2234
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: process
>    Affects Versions: 3.4.2
>            Reporter: Stephen Mallette
>            Priority: Major
>
> Provide for a {{typeOf()}} predicate that allows for testing the type of an 
> object which would enable neat things like:
> {code}
> g.V().outE().has('weight',gt(0.1)).inV().path().unfold().is(typeOf(VERTEX))
> {code}
> See the linked DISCUSS thread for more information.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to