hsyuan commented on a change in pull request #1486: [WIP][CALCITE-3388] 
StackOverflowError for creating structured RelDataType from class type
URL: https://github.com/apache/calcite/pull/1486#discussion_r331729828
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java
 ##########
 @@ -69,17 +69,33 @@ public JavaTypeFactoryImpl(RelDataTypeSystem typeSystem) {
     super(typeSystem);
   }
 
+  /**
+   * Create a structured {@link RelDataType} from java type,
+   * throw exception if recursion founded.
+   */
   public RelDataType createStructType(Class type) {
+    Map<Type, Type> edges = new HashMap<>();
+    return createStructType(type, edges);
+  }
+
+  private RelDataType createStructType(Class type, Map<Type, Type> edges) {
+    Type checkType = edges.get(type);
+    while (checkType != null) {
+      if (checkType.equals(type)) {
+        throw new RuntimeException("Recursion for creating struct type 
unsupported");
+      }
+      checkType = edges.get(checkType);
+    }
     final List<RelDataTypeField> list = new ArrayList<>();
     for (Field field : type.getFields()) {
       if (!Modifier.isStatic(field.getModifiers())) {
-        // FIXME: watch out for recursion
 
 Review comment:
   Haha, :)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to