You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2022/11/17 09:50:34 UTC
[GitHub] [hive] tarak271 opened a new pull request, #3774: HIVE-26744 - Add array_max and array_min UDFs
tarak271 opened a new pull request, #3774:
URL: https://github.com/apache/hive/pull/3774
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
3. Ensure you have added or run the appropriate tests for your PR:
4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX: Your PR title ...'.
5. Be sure to keep the PR description updated to reflect all changes.
6. Please write your PR title to summarize what this PR proposes.
7. If possible, provide a concise example to reproduce the issue for a faster review.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
Implement array_max and array_min UDFs in Hive
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
Enhancements that are already implemented in Spark
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
If no, write 'No'.
--> No
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
Created Junit tests as well as qtests as part of this change
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027939852
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
Review Comment:
This isn't used anywhere in this patch. If this is planned to be used in some Jira, please introduce this in that patch.
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
Review Comment:
This isn't used anywhere in this patch. If this is planned to be used in some Jira, please introduce this in that patch.
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027990680
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
Review Comment:
I think this enum might not be required and we can call `initialize` in the sub-classes.
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] sonarcloud[bot] commented on pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #3774:
URL: https://github.com/apache/hive/pull/3774#issuecomment-1320701967
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=3774)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [2 Bugs](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [9 Code Smells](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=coverage&view=list) No Coverage information
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=duplicated_lines_density&view=list) No Duplication information
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] tarak271 commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
tarak271 commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1028349771
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
Review Comment:
Removed ENUM
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027990680
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
Review Comment:
I think this enum might not be required and we can call the initialize in the sub-classes.
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] tarak271 commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
tarak271 commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1028349448
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
+
+ // Check if wrong number of arguments were passed
+ checkArgsSize(arguments, minArgCount, maxArgCount);
+
+ // Check if the argument is of category LIST or not
+ checkArgCategory(arguments, ARRAY_IDX, ObjectInspector.Category.LIST, funcName,
+ org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME);
+
+ //return ObjectInspectors based on expected output type
+ arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
+ argumentOIs = arguments;
+ if (outputCategory == ObjectInspector.Category.LIST) {
+ return initListOI(arguments);
+ } else {
+ return initOI(arguments);
+ }
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == minArgCount);
+ return funcName.toString().toLowerCase() + "(" + children[ARRAY_IDX] + ")";
+ }
+
+ List<Object> convertArray(List objects) {
Review Comment:
Removed unused function
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
+
+ // Check if wrong number of arguments were passed
+ checkArgsSize(arguments, minArgCount, maxArgCount);
+
+ // Check if the argument is of category LIST or not
+ checkArgCategory(arguments, ARRAY_IDX, ObjectInspector.Category.LIST, funcName,
+ org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME);
+
+ //return ObjectInspectors based on expected output type
+ arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
+ argumentOIs = arguments;
+ if (outputCategory == ObjectInspector.Category.LIST) {
+ return initListOI(arguments);
+ } else {
+ return initOI(arguments);
+ }
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == minArgCount);
+ return funcName.toString().toLowerCase() + "(" + children[ARRAY_IDX] + ")";
+ }
+
+ List<Object> convertArray(List objects) {
+ List<Object> ret = new ArrayList<>();
+ for (Object o : objects) {
+ ret.add(converter.convert(o));
+ }
+ return ret;
+ }
+
+ void checkArgCategory(ObjectInspector[] arguments, int idx, Enum category,
+ FUNC_NAMES functionName, String typeName) throws UDFArgumentTypeException {
+
+ if (!arguments[idx].getCategory().equals(category)) {
+ throw new UDFArgumentTypeException(idx,
+ "\"" + typeName + "\" "
+ + "expected at function " + functionName + ", but "
+ + "\"" + arguments[idx].getTypeName() + "\" "
+ + "is found");
+ }
+ }
+
+ void checkArgIntPrimitiveCategory(PrimitiveObjectInspector objectInspector,
Review Comment:
Removed unused function
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] sonarcloud[bot] commented on pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #3774:
URL: https://github.com/apache/hive/pull/3774#issuecomment-1323812891
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=3774)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=coverage&view=list) No Coverage information
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=duplicated_lines_density&view=list) No Duplication information
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] ayushtkn merged pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
ayushtkn merged PR #3774:
URL: https://github.com/apache/hive/pull/3774
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027999992
##########
ql/src/test/queries/clientpositive/udf_array_min.q:
##########
@@ -0,0 +1,16 @@
+--! qt:dataset:src
+set hive.fetch.task.conversion=more;
Review Comment:
Is this required here?
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1028911711
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final String functionName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(String functionName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.functionName = functionName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
Review Comment:
Are the functions invoked in `initialize` same for all array UDFs?
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027960338
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
+
+ // Check if wrong number of arguments were passed
+ checkArgsSize(arguments, minArgCount, maxArgCount);
+
+ // Check if the argument is of category LIST or not
+ checkArgCategory(arguments, ARRAY_IDX, ObjectInspector.Category.LIST, funcName,
+ org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME);
+
+ //return ObjectInspectors based on expected output type
+ arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
+ argumentOIs = arguments;
+ if (outputCategory == ObjectInspector.Category.LIST) {
+ return initListOI(arguments);
+ } else {
+ return initOI(arguments);
+ }
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == minArgCount);
+ return funcName.toString().toLowerCase() + "(" + children[ARRAY_IDX] + ")";
+ }
+
+ List<Object> convertArray(List objects) {
+ List<Object> ret = new ArrayList<>();
+ for (Object o : objects) {
+ ret.add(converter.convert(o));
+ }
+ return ret;
+ }
+
+ void checkArgCategory(ObjectInspector[] arguments, int idx, Enum category,
+ FUNC_NAMES functionName, String typeName) throws UDFArgumentTypeException {
+
+ if (!arguments[idx].getCategory().equals(category)) {
+ throw new UDFArgumentTypeException(idx,
+ "\"" + typeName + "\" "
+ + "expected at function " + functionName + ", but "
+ + "\"" + arguments[idx].getTypeName() + "\" "
+ + "is found");
+ }
+ }
+
+ void checkArgIntPrimitiveCategory(PrimitiveObjectInspector objectInspector,
Review Comment:
Unused function in this patch
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027939967
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
Review Comment:
These lines (L41-L45) aren't used anywhere in this patch. If this is planned to be used in some Jira, please introduce this in that patch.
https://github.com/apache/hive/pull/3774/files#diff-db6db011493631c75a28aac125e0693890f0fb96abdccbdd3bc088e641f40d4aR41-R45
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] sonarcloud[bot] commented on pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #3774:
URL: https://github.com/apache/hive/pull/3774#issuecomment-1324388371
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=3774)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=coverage&view=list) No Coverage information
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=duplicated_lines_density&view=list) No Duplication information
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1028909989
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
+
+ // Check if wrong number of arguments were passed
+ checkArgsSize(arguments, minArgCount, maxArgCount);
+
+ // Check if the argument is of category LIST or not
+ checkArgCategory(arguments, ARRAY_IDX, ObjectInspector.Category.LIST, funcName,
+ org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME);
+
+ //return ObjectInspectors based on expected output type
+ arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
+ argumentOIs = arguments;
+ if (outputCategory == ObjectInspector.Category.LIST) {
+ return initListOI(arguments);
+ } else {
+ return initOI(arguments);
+ }
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == minArgCount);
+ return funcName.toString().toLowerCase() + "(" + children[ARRAY_IDX] + ")";
+ }
+
+ List<Object> convertArray(List objects) {
+ List<Object> ret = new ArrayList<>();
+ for (Object o : objects) {
+ ret.add(converter.convert(o));
+ }
+ return ret;
+ }
+
+ void checkArgCategory(ObjectInspector[] arguments, int idx, Enum category,
+ FUNC_NAMES functionName, String typeName) throws UDFArgumentTypeException {
+
+ if (!arguments[idx].getCategory().equals(category)) {
+ throw new UDFArgumentTypeException(idx,
+ "\"" + typeName + "\" "
+ + "expected at function " + functionName + ", but "
+ + "\"" + arguments[idx].getTypeName() + "\" "
+ + "is found");
+ }
+ }
+
+ void checkArgIntPrimitiveCategory(PrimitiveObjectInspector objectInspector,
+ FUNC_NAMES functionName, int idx) throws UDFArgumentTypeException {
+
+ switch (objectInspector.getPrimitiveCategory()) {
+ case SHORT:
+ case INT:
+ case LONG:
+ break;
+ default:
+ throw new UDFArgumentTypeException(0, "Argument " + idx
+ + " of function " + functionName + " must be \""
+ + serdeConstants.SMALLINT_TYPE_NAME + "\""
+ + " or \"" + serdeConstants.INT_TYPE_NAME + "\""
+ + " or \"" + serdeConstants.BIGINT_TYPE_NAME + "\", but \""
+ + objectInspector.getTypeName() + "\" was found.");
+ }
+ }
+
+ ObjectInspector initOI(ObjectInspector[] arguments) {
+
+ GenericUDFUtils.ReturnObjectInspectorResolver returnOIResolver =
+ new GenericUDFUtils.ReturnObjectInspectorResolver(true);
+
+ ObjectInspector elementObjectInspector =
+ ((ListObjectInspector) (arguments[0])).getListElementObjectInspector();
+
+ ObjectInspector returnOI = returnOIResolver.get(elementObjectInspector);
+ converter = ObjectInspectorConverters.getConverter(elementObjectInspector, returnOI);
+ return returnOI;
Review Comment:
@tarak271 , I still see the incorrect indentation.
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] tarak271 commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
tarak271 commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1028350086
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
Review Comment:
Removed ENUM
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] tarak271 commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
tarak271 commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1028349236
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
Review Comment:
Removed unused variables
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027939852
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
Review Comment:
These lines aren't used anywhere in this patch. If this is planned to be used in some Jira, please introduce this in that patch.
https://github.com/apache/hive/pull/3774/files#diff-db6db011493631c75a28aac125e0693890f0fb96abdccbdd3bc088e641f40d4aR41-R44
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1028909989
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
+
+ // Check if wrong number of arguments were passed
+ checkArgsSize(arguments, minArgCount, maxArgCount);
+
+ // Check if the argument is of category LIST or not
+ checkArgCategory(arguments, ARRAY_IDX, ObjectInspector.Category.LIST, funcName,
+ org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME);
+
+ //return ObjectInspectors based on expected output type
+ arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
+ argumentOIs = arguments;
+ if (outputCategory == ObjectInspector.Category.LIST) {
+ return initListOI(arguments);
+ } else {
+ return initOI(arguments);
+ }
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == minArgCount);
+ return funcName.toString().toLowerCase() + "(" + children[ARRAY_IDX] + ")";
+ }
+
+ List<Object> convertArray(List objects) {
+ List<Object> ret = new ArrayList<>();
+ for (Object o : objects) {
+ ret.add(converter.convert(o));
+ }
+ return ret;
+ }
+
+ void checkArgCategory(ObjectInspector[] arguments, int idx, Enum category,
+ FUNC_NAMES functionName, String typeName) throws UDFArgumentTypeException {
+
+ if (!arguments[idx].getCategory().equals(category)) {
+ throw new UDFArgumentTypeException(idx,
+ "\"" + typeName + "\" "
+ + "expected at function " + functionName + ", but "
+ + "\"" + arguments[idx].getTypeName() + "\" "
+ + "is found");
+ }
+ }
+
+ void checkArgIntPrimitiveCategory(PrimitiveObjectInspector objectInspector,
+ FUNC_NAMES functionName, int idx) throws UDFArgumentTypeException {
+
+ switch (objectInspector.getPrimitiveCategory()) {
+ case SHORT:
+ case INT:
+ case LONG:
+ break;
+ default:
+ throw new UDFArgumentTypeException(0, "Argument " + idx
+ + " of function " + functionName + " must be \""
+ + serdeConstants.SMALLINT_TYPE_NAME + "\""
+ + " or \"" + serdeConstants.INT_TYPE_NAME + "\""
+ + " or \"" + serdeConstants.BIGINT_TYPE_NAME + "\", but \""
+ + objectInspector.getTypeName() + "\" was found.");
+ }
+ }
+
+ ObjectInspector initOI(ObjectInspector[] arguments) {
+
+ GenericUDFUtils.ReturnObjectInspectorResolver returnOIResolver =
+ new GenericUDFUtils.ReturnObjectInspectorResolver(true);
+
+ ObjectInspector elementObjectInspector =
+ ((ListObjectInspector) (arguments[0])).getListElementObjectInspector();
+
+ ObjectInspector returnOI = returnOIResolver.get(elementObjectInspector);
+ converter = ObjectInspectorConverters.getConverter(elementObjectInspector, returnOI);
+ return returnOI;
Review Comment:
@tarak271 , I still see the incorrect indentation.
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] tarak271 commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
tarak271 commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1028350384
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
+
+ // Check if wrong number of arguments were passed
+ checkArgsSize(arguments, minArgCount, maxArgCount);
+
+ // Check if the argument is of category LIST or not
+ checkArgCategory(arguments, ARRAY_IDX, ObjectInspector.Category.LIST, funcName,
+ org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME);
+
+ //return ObjectInspectors based on expected output type
+ arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
+ argumentOIs = arguments;
+ if (outputCategory == ObjectInspector.Category.LIST) {
+ return initListOI(arguments);
+ } else {
+ return initOI(arguments);
+ }
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == minArgCount);
+ return funcName.toString().toLowerCase() + "(" + children[ARRAY_IDX] + ")";
+ }
+
+ List<Object> convertArray(List objects) {
+ List<Object> ret = new ArrayList<>();
+ for (Object o : objects) {
+ ret.add(converter.convert(o));
+ }
+ return ret;
+ }
+
+ void checkArgCategory(ObjectInspector[] arguments, int idx, Enum category,
+ FUNC_NAMES functionName, String typeName) throws UDFArgumentTypeException {
+
+ if (!arguments[idx].getCategory().equals(category)) {
+ throw new UDFArgumentTypeException(idx,
+ "\"" + typeName + "\" "
+ + "expected at function " + functionName + ", but "
+ + "\"" + arguments[idx].getTypeName() + "\" "
+ + "is found");
+ }
+ }
+
+ void checkArgIntPrimitiveCategory(PrimitiveObjectInspector objectInspector,
+ FUNC_NAMES functionName, int idx) throws UDFArgumentTypeException {
+
+ switch (objectInspector.getPrimitiveCategory()) {
+ case SHORT:
+ case INT:
+ case LONG:
+ break;
+ default:
+ throw new UDFArgumentTypeException(0, "Argument " + idx
+ + " of function " + functionName + " must be \""
+ + serdeConstants.SMALLINT_TYPE_NAME + "\""
+ + " or \"" + serdeConstants.INT_TYPE_NAME + "\""
+ + " or \"" + serdeConstants.BIGINT_TYPE_NAME + "\", but \""
+ + objectInspector.getTypeName() + "\" was found.");
+ }
+ }
+
+ ObjectInspector initOI(ObjectInspector[] arguments) {
+
+ GenericUDFUtils.ReturnObjectInspectorResolver returnOIResolver =
+ new GenericUDFUtils.ReturnObjectInspectorResolver(true);
+
+ ObjectInspector elementObjectInspector =
+ ((ListObjectInspector) (arguments[0])).getListElementObjectInspector();
+
+ ObjectInspector returnOI = returnOIResolver.get(elementObjectInspector);
+ converter = ObjectInspectorConverters.getConverter(elementObjectInspector, returnOI);
+ return returnOI;
Review Comment:
Corrected indentation
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027995616
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
Review Comment:
Better to call `initialize` in sub-classes and maintain common function like `checkArgsSize ` and `checkArgCategory ` here. This will remove the need of maintaining function types (enums) in the code.
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] sonarcloud[bot] commented on pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #3774:
URL: https://github.com/apache/hive/pull/3774#issuecomment-1319009247
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=3774)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [2 Bugs](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [14 Code Smells](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=coverage&view=list) No Coverage information
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=duplicated_lines_density&view=list) No Duplication information
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] sonarcloud[bot] commented on pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #3774:
URL: https://github.com/apache/hive/pull/3774#issuecomment-1320382739
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=3774)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [2 Bugs](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [14 Code Smells](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=coverage&view=list) No Coverage information
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=duplicated_lines_density&view=list) No Duplication information
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027950232
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
+
+ // Check if wrong number of arguments were passed
+ checkArgsSize(arguments, minArgCount, maxArgCount);
+
+ // Check if the argument is of category LIST or not
+ checkArgCategory(arguments, ARRAY_IDX, ObjectInspector.Category.LIST, funcName,
+ org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME);
+
+ //return ObjectInspectors based on expected output type
+ arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
+ argumentOIs = arguments;
+ if (outputCategory == ObjectInspector.Category.LIST) {
+ return initListOI(arguments);
+ } else {
+ return initOI(arguments);
+ }
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == minArgCount);
+ return funcName.toString().toLowerCase() + "(" + children[ARRAY_IDX] + ")";
+ }
+
+ List<Object> convertArray(List objects) {
Review Comment:
Unused function in this patch
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027995616
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
Review Comment:
Better to call `initialize` in sub-classes and maintain common function like `checkArgsSize` and `checkArgCategory` here. This will remove the need of maintaining function types (enums) in the code.
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1028042309
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
+
+ // Check if wrong number of arguments were passed
+ checkArgsSize(arguments, minArgCount, maxArgCount);
+
+ // Check if the argument is of category LIST or not
+ checkArgCategory(arguments, ARRAY_IDX, ObjectInspector.Category.LIST, funcName,
+ org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME);
+
+ //return ObjectInspectors based on expected output type
+ arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
+ argumentOIs = arguments;
+ if (outputCategory == ObjectInspector.Category.LIST) {
+ return initListOI(arguments);
+ } else {
+ return initOI(arguments);
+ }
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == minArgCount);
+ return funcName.toString().toLowerCase() + "(" + children[ARRAY_IDX] + ")";
+ }
+
+ List<Object> convertArray(List objects) {
+ List<Object> ret = new ArrayList<>();
+ for (Object o : objects) {
+ ret.add(converter.convert(o));
+ }
+ return ret;
+ }
+
+ void checkArgCategory(ObjectInspector[] arguments, int idx, Enum category,
+ FUNC_NAMES functionName, String typeName) throws UDFArgumentTypeException {
+
+ if (!arguments[idx].getCategory().equals(category)) {
+ throw new UDFArgumentTypeException(idx,
+ "\"" + typeName + "\" "
+ + "expected at function " + functionName + ", but "
+ + "\"" + arguments[idx].getTypeName() + "\" "
+ + "is found");
+ }
+ }
+
+ void checkArgIntPrimitiveCategory(PrimitiveObjectInspector objectInspector,
+ FUNC_NAMES functionName, int idx) throws UDFArgumentTypeException {
+
+ switch (objectInspector.getPrimitiveCategory()) {
+ case SHORT:
+ case INT:
+ case LONG:
+ break;
+ default:
+ throw new UDFArgumentTypeException(0, "Argument " + idx
+ + " of function " + functionName + " must be \""
+ + serdeConstants.SMALLINT_TYPE_NAME + "\""
+ + " or \"" + serdeConstants.INT_TYPE_NAME + "\""
+ + " or \"" + serdeConstants.BIGINT_TYPE_NAME + "\", but \""
+ + objectInspector.getTypeName() + "\" was found.");
+ }
+ }
+
+ ObjectInspector initOI(ObjectInspector[] arguments) {
+
+ GenericUDFUtils.ReturnObjectInspectorResolver returnOIResolver =
+ new GenericUDFUtils.ReturnObjectInspectorResolver(true);
+
+ ObjectInspector elementObjectInspector =
+ ((ListObjectInspector) (arguments[0])).getListElementObjectInspector();
+
+ ObjectInspector returnOI = returnOIResolver.get(elementObjectInspector);
+ converter = ObjectInspectorConverters.getConverter(elementObjectInspector, returnOI);
+ return returnOI;
Review Comment:
nit: Indentation
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] sonarcloud[bot] commented on pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #3774:
URL: https://github.com/apache/hive/pull/3774#issuecomment-1322539781
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=3774)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [2 Bugs](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [11 Code Smells](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=coverage&view=list) No Coverage information
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=duplicated_lines_density&view=list) No Duplication information
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] sonarcloud[bot] commented on pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #3774:
URL: https://github.com/apache/hive/pull/3774#issuecomment-1318424435
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=3774)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG) [2 Bugs](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=3774&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL) [16 Code Smells](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=3774&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=coverage&view=list) No Coverage information
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=3774&metric=duplicated_lines_density&view=list) No Duplication information
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027999992
##########
ql/src/test/queries/clientpositive/udf_array_min.q:
##########
@@ -0,0 +1,16 @@
+--! qt:dataset:src
+set hive.fetch.task.conversion=more;
Review Comment:
Is this required here?
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027939967
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
Review Comment:
These lines aren't used anywhere in this patch. If this is planned to be used in some Jira, please introduce this in that patch.
https://github.com/apache/hive/pull/3774/files#diff-db6db011493631c75a28aac125e0693890f0fb96abdccbdd3bc088e641f40d4aR41-R45
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1027939852
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
Review Comment:
This isn't used anywhere in this patch. If this is planned to be used in some Jira, please introduce this in that patch.
https://github.com/apache/hive/pull/3774/files#diff-db6db011493631c75a28aac125e0693890f0fb96abdccbdd3bc088e641f40d4aR41-R44
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] tarak271 commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
tarak271 commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1029355567
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final String functionName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(String functionName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.functionName = functionName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
Review Comment:
Yes, all the array functions should be using the same initialize method
if the output type is non-list, then regular return type will be used
checkArgSize and checkArgCategory are going to be same for all argument values alone differ which are coming from constructor
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] SourabhBadhya commented on a diff in pull request #3774: HIVE-26744 - Add array_max and array_min UDFs
Posted by GitBox <gi...@apache.org>.
SourabhBadhya commented on code in PR #3774:
URL: https://github.com/apache/hive/pull/3774#discussion_r1028909989
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.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
+ *
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.serde.serdeConstants;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract GenericUDF for array functions
+ */
+
+public abstract class AbstractGenericUDFArrayBase extends GenericUDF {
+
+ static final int ARRAY_IDX = 0;
+ static final int ARRAY2_IDX = 1;
+ static final int START_IDX = 1;
+ static final int LENGTH_IDX = 2;
+ static final int SEPARATOR_IDX = 1;
+ static final int REPLACE_NULL_IDX = 2;
+
+ private final int minArgCount;
+ private final int maxArgCount;
+ private final ObjectInspector.Category outputCategory;
+
+ private final FUNC_NAMES funcName;
+
+ transient ListObjectInspector arrayOI;
+ transient ObjectInspector[] argumentOIs;
+
+ transient Converter converter;
+
+ public AbstractGenericUDFArrayBase(FUNC_NAMES funcName, int minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
+ this.funcName = funcName;
+ this.minArgCount = minArgCount;
+ this.maxArgCount = maxArgCount;
+ this.outputCategory = outputCategory;
+ }
+
+ enum FUNC_NAMES {
+ ARRAY_MAX, ARRAY_MIN, ARRAY_DISTINCT, ARRAY_SLICE, ARRAY_JOIN, ARRAY_EXCEPT, ARRAY_INTERSECT
+ }
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
+
+ // Check if wrong number of arguments were passed
+ checkArgsSize(arguments, minArgCount, maxArgCount);
+
+ // Check if the argument is of category LIST or not
+ checkArgCategory(arguments, ARRAY_IDX, ObjectInspector.Category.LIST, funcName,
+ org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME);
+
+ //return ObjectInspectors based on expected output type
+ arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
+ argumentOIs = arguments;
+ if (outputCategory == ObjectInspector.Category.LIST) {
+ return initListOI(arguments);
+ } else {
+ return initOI(arguments);
+ }
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == minArgCount);
+ return funcName.toString().toLowerCase() + "(" + children[ARRAY_IDX] + ")";
+ }
+
+ List<Object> convertArray(List objects) {
+ List<Object> ret = new ArrayList<>();
+ for (Object o : objects) {
+ ret.add(converter.convert(o));
+ }
+ return ret;
+ }
+
+ void checkArgCategory(ObjectInspector[] arguments, int idx, Enum category,
+ FUNC_NAMES functionName, String typeName) throws UDFArgumentTypeException {
+
+ if (!arguments[idx].getCategory().equals(category)) {
+ throw new UDFArgumentTypeException(idx,
+ "\"" + typeName + "\" "
+ + "expected at function " + functionName + ", but "
+ + "\"" + arguments[idx].getTypeName() + "\" "
+ + "is found");
+ }
+ }
+
+ void checkArgIntPrimitiveCategory(PrimitiveObjectInspector objectInspector,
+ FUNC_NAMES functionName, int idx) throws UDFArgumentTypeException {
+
+ switch (objectInspector.getPrimitiveCategory()) {
+ case SHORT:
+ case INT:
+ case LONG:
+ break;
+ default:
+ throw new UDFArgumentTypeException(0, "Argument " + idx
+ + " of function " + functionName + " must be \""
+ + serdeConstants.SMALLINT_TYPE_NAME + "\""
+ + " or \"" + serdeConstants.INT_TYPE_NAME + "\""
+ + " or \"" + serdeConstants.BIGINT_TYPE_NAME + "\", but \""
+ + objectInspector.getTypeName() + "\" was found.");
+ }
+ }
+
+ ObjectInspector initOI(ObjectInspector[] arguments) {
+
+ GenericUDFUtils.ReturnObjectInspectorResolver returnOIResolver =
+ new GenericUDFUtils.ReturnObjectInspectorResolver(true);
+
+ ObjectInspector elementObjectInspector =
+ ((ListObjectInspector) (arguments[0])).getListElementObjectInspector();
+
+ ObjectInspector returnOI = returnOIResolver.get(elementObjectInspector);
+ converter = ObjectInspectorConverters.getConverter(elementObjectInspector, returnOI);
+ return returnOI;
Review Comment:
@tarak271 , I still the same indentation.
--
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org