clazz) {
+ try {
+ return clazz.cast(actual.get(nth).value);
+ } catch (ClassCastException e) {
+ throw new TypeException(null, clazz, actual.get(nth).type, actual.get(nth).value);
+ }
+ }
+
+ public interface Arity {
+ void check(String methodName, List> params);
+
+ Arity NULLARY = Arity.of(0);
+ Arity UNARY = Arity.of(1);
+ Arity BINARY = Arity.of(2);
+
+ static Arity of(int count) {
+ return (methodName, params) -> {
+ if (params.size() != count) {
+ throw new ArityException(null, methodName, count, params.size());
+ }
+ };
+ }
+
+ static Arity min(int count) {
+ return (methodName, params) -> {
+ if (params.size() < count) {
+ throw new ArityException(null, "wrong number of arguments in call to '" + methodName
+ + "'. Expected at least " + count + " got " + params.size() + ".");
+ }
+ };
+ }
+
+ static Arity max(int count) {
+ return (methodName, params) -> {
+ if (params.size() > count) {
+ throw new ArityException(null, "wrong number of arguments in call to '" + methodName
+ + "'. Expected at most " + count + " got " + params.size() + ".");
+ }
+ };
+ }
+ }
+}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/hplsql/objects/Table.java b/fe/fe-core/src/main/java/org/apache/doris/hplsql/objects/Table.java
new file mode 100644
index 00000000000000..57aad8e1d1cf5b
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/hplsql/objects/Table.java
@@ -0,0 +1,224 @@
+// 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.
+// This file is copied from
+// https://github.com/apache/hive/blob/master/hplsql/src/main/java/org/apache/hive/hplsql/objects/Table.java
+// and modified by Doris
+
+package org.apache.doris.hplsql.objects;
+
+import org.apache.doris.hplsql.ColumnDefinition;
+import org.apache.doris.hplsql.Row;
+import org.apache.doris.hplsql.Var;
+import org.apache.doris.hplsql.executor.QueryResult;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Oracle's PL/SQL Table/associative array.
+ *
+ * Tables can be modelled after a corresponding Hive table or they can be created manually.
+ *
+ * 1. Model the table after the emp Hive table
+ * TYPE t_tab IS TABLE OF emp%ROWTYPE INDEX BY BINARY_INTEGER;
+ *
+ * 2. Model the table after a column of a Hive table (emp.name). This table will hold a single column only.
+ * TYPE t_tab IS TABLE OF emp.name%TYPE INDEX BY BINARY_INTEGER;
+ *
+ * 3. Or you can specify the column manually. This table will hold one column only.
+ * TYPE t_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
+ *
+ * In the first case the values will be records where each key in the record matches the columns to the corresponding
+ * table.
+ * tab(key).col_name;
+ *
+ * In the last two cases the values will represent scalars, but they stored in a record with a single key.
+ * tab(key)
+ *
+ * Iteration logic uses the first/last next and prior methods.
+ * First/last returns a key, next/prior gives back the next or previous key based on the key passed in.
+ */
+public class Table implements HplObject {
+ private final TableClass hplClass;
+ private final Map