You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2023/01/04 03:47:00 UTC

[jira] [Work logged] (HIVE-26774) Implement array_slice UDF to get the subset of elements from an array (subarray)

     [ https://issues.apache.org/jira/browse/HIVE-26774?focusedWorklogId=836788&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-836788 ]

ASF GitHub Bot logged work on HIVE-26774:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 04/Jan/23 03:46
            Start Date: 04/Jan/23 03:46
    Worklog Time Spent: 10m 
      Work Description: SourabhBadhya commented on code in PR #3893:
URL: https://github.com/apache/hive/pull/3893#discussion_r1061114658


##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFArraySlice.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * GenericUDFArraySlice.
+ */
+@Description(name = "array_slice", value = "_FUNC_(array, start, length) - Returns the subset or range of elements from"

Review Comment:
   Is there any particular reason on why we use these inputs - i.e. `array_slice(array, start, length)` ? 
   
   Because as far as I know in most programming languages, we usually provide start index and end index.
   
   Please let me know if this is inspired from some place in SQL languages, so that we have valid reason to justify these inputs. 





Issue Time Tracking
-------------------

    Worklog Id:     (was: 836788)
    Time Spent: 40m  (was: 0.5h)

> Implement array_slice UDF to get the subset of elements from an array (subarray)
> --------------------------------------------------------------------------------
>
>                 Key: HIVE-26774
>                 URL: https://issues.apache.org/jira/browse/HIVE-26774
>             Project: Hive
>          Issue Type: Sub-task
>          Components: Hive
>            Reporter: Taraka Rama Rao Lethavadla
>            Assignee: Taraka Rama Rao Lethavadla
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> *array_slice(array, start, length)* - Returns the subset or range of elements from an array (subarray).
> Example:
>   
> {noformat}
> > SELECT array_slice(array(1, 2, 3,4), 2,2) FROM src LIMIT 1;
> 3,4{noformat}
> Returns empty list if start/length are out of range of the array



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