carloea2 commented on code in PR #4268:
URL: https://github.com/apache/texera/pull/4268#discussion_r3104574425


##########
frontend/src/app/workspace/types/workflow-compiling.interface.ts:
##########
@@ -70,8 +70,50 @@ export type CompilationStateInfo = Readonly<
       operatorErrors: Readonly<Record<string, WorkflowFatalError>>;
     }
 >;
+
 // possible types of an attribute
-export type AttributeType = "string" | "integer" | "double" | "boolean" | 
"long" | "timestamp" | "binary"; // schema: an array of attribute names and 
types
+// Canonical frontend / JSON schema names
+export type AttributeType =
+  | "string"
+  | "integer"
+  | "long"
+  | "double"
+  | "boolean"
+  | "timestamp"
+  | "binary"
+  | "large_binary";
+
+// Java enum constant names (AttributeType.java)
+export const JAVA_ATTRIBUTE_TYPE_NAMES = [

Review Comment:
   The reason is to unify them since there are mismatchs between python namings 
and java namings, and it may cause issues in the backend.



##########
frontend/src/app/workspace/service/code-editor/ui-udf-parameters-parser.service.ts:
##########
@@ -0,0 +1,435 @@
+/**
+ * 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.
+ */
+
+import { Injectable } from "@angular/core";
+import {
+  AttributeType,
+  JavaAttributeTypeName,
+  PythonAttributeTypeName,
+  SchemaAttribute,
+  JAVA_ATTRIBUTE_TYPE_NAMES,
+  PYTHON_ATTRIBUTE_TYPE_NAMES,
+} from "../../types/workflow-compiling.interface";
+
+export interface UiUdfParameter {
+  attribute: SchemaAttribute;
+  value: string;
+}
+
+type ParserAttributeTypeToken = JavaAttributeTypeName | 
PythonAttributeTypeName;
+
+const ATTRIBUTE_TYPE_TOKEN_TO_CANONICAL: 
Readonly<Record<ParserAttributeTypeToken, AttributeType>> = {
+  STRING: "string",
+  INTEGER: "integer",
+  INT: "integer",
+  LONG: "long",
+  DOUBLE: "double",
+  BOOLEAN: "boolean",
+  BOOL: "boolean",
+  TIMESTAMP: "timestamp",
+  BINARY: "binary",
+  LARGE_BINARY: "large_binary",
+};
+
+const JAVA_ATTRIBUTE_TYPE_NAME_SET = new 
Set<string>(JAVA_ATTRIBUTE_TYPE_NAMES);
+const PYTHON_ATTRIBUTE_TYPE_NAME_SET = new 
Set<string>(PYTHON_ATTRIBUTE_TYPE_NAMES);
+const SUPPORTED_UI_PARAMETER_ATTRIBUTE_TYPES = new Set<AttributeType>([
+  "string",
+  "integer",
+  "long",
+  "double",
+  "boolean",
+  "timestamp",
+]);
+
+@Injectable({ providedIn: "root" })
+export class UiUdfParametersParserService {
+  private static readonly SUPPORTED_CLASSES = [
+    "ProcessTupleOperator",
+    "ProcessBatchOperator",
+    "ProcessTableOperator",
+    "GenerateOperator",
+  ];
+
+  parse(code: string): UiUdfParameter[] {
+    if (!code) {
+      return [];
+    }
+
+    const sanitizedCode = this.stripCommentsAndDocstrings(code);
+    const classPattern = 
UiUdfParametersParserService.SUPPORTED_CLASSES.join("|");
+    const classRegex = new RegExp(
+      
`class\\s+(${classPattern})\\s*\\([^)]*\\)\\s*:[\\s\\S]*?(?=\\nclass\\s+\\w+\\s*\\(|$)`,
+      "g"
+    );
+
+    const parsed: UiUdfParameter[] = [];
+    const existingNames = new Set<string>();
+
+    let classMatch: RegExpExecArray | null;
+    while ((classMatch = classRegex.exec(sanitizedCode)) !== null) {
+      const classBlock = classMatch[0];
+
+      for (const args of this.extractUiParameterArgumentLists(classBlock)) {
+        const argumentTokens = this.tokenizeArguments(args);
+        const extracted = this.extractParameter(argumentTokens);
+        if (!extracted || 
existingNames.has(extracted.attribute.attributeName)) {
+          continue;
+        }
+
+        existingNames.add(extracted.attribute.attributeName);
+        parsed.push(extracted);
+      }
+    }
+
+    return parsed;
+  }
+
+  private stripCommentsAndDocstrings(code: string): string {

Review Comment:
   Yes, I did not check, do you have something in mind meanwhile?



-- 
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]

Reply via email to