You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by "Tanujit Ghosh (JIRA)" <ji...@apache.org> on 2013/08/05 04:57:48 UTC
[jira] [Commented] (DRILL-162) Implement substring function
[ https://issues.apache.org/jira/browse/DRILL-162?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13729082#comment-13729082 ]
Tanujit Ghosh commented on DRILL-162:
-------------------------------------
I tried applying the patch, but its failing
[tanujit@legolas incubator-drill]$ git apply --check substring_function.patch
error: patch failed: sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Substring.java:1
error: sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Substring.java: patch does not apply
error: patch failed: sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java:182
error: sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java: patch does not apply
error: patch failed: sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java:185
error: sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java: patch does not apply
I think the version of Substring.java in master is different from the one you have based the patch on
[tanujit@legolas incubator-drill]$ cat sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Substring.java
/*******************************************************************************
* 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.drill.exec.expr.fn.impl;
import org.apache.drill.common.expression.ArgumentValidators;
import org.apache.drill.common.expression.CallProvider;
import org.apache.drill.common.expression.FunctionDefinition;
import org.apache.drill.common.expression.OutputTypeDeterminer;
import org.apache.drill.exec.expr.DrillFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.Output;
import org.apache.drill.exec.expr.annotations.Param;
import org.apache.drill.exec.record.RecordBatch;
import org.apache.drill.exec.vector.*;
// TODO: implement optional length parameter
// implement negative start position
@FunctionTemplate(name = "substring",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
public class Substring implements DrillFunc {
@Param VarCharHolder string;
@Param BigIntHolder offset;
@Param BigIntHolder length;
@Output VarCharHolder out;
@Override
public void setup(RecordBatch incoming) { }
@Override
public void eval() {
out.buffer = string.buffer;
out.start = (int)offset.value;
out.end = (int)length.value;
}
public static class Provider implements CallProvider {
@Override
public FunctionDefinition[] getFunctionDefintions() {
return new FunctionDefinition[] {
FunctionDefinition.simple("substring",
new ArgumentValidators.AnyTypeAllowed(3),
new OutputTypeDeterminer.SameAsFirstInput(),
"substring",
"substr")
};
}
}
}
> Implement substring function
> ----------------------------
>
> Key: DRILL-162
> URL: https://issues.apache.org/jira/browse/DRILL-162
> Project: Apache Drill
> Issue Type: New Feature
> Reporter: Ben Becker
> Assignee: Ben Becker
> Attachments: substring_function.patch
>
>
> Implement SUBSTRING with support for byte and character (UTF-8) sequences.
> {code}
> SUBSTRING ( expression , start, length )
> {code}
> h5. Types:
> {{expression}}: VARCHAR or VARBINARY
> {{start}}: Literal BIGINT
> {{length}}: Literal BIGINT
> {{Returns}}: Same type as the {{expression}} argument
> h5. Arguments:
> {{start}}: position within the {{expression}} value the return value will start from
> {{length}}: number of subsequent characters or bytes to return.
> h5. Aliases:
> {{SUBSTR}}
> {{BYTE_SUBSTR}}
> h5. Return Value:
> Returns the specified portion of the input string.
> h5. Notes on behavior:
> - If the start position is negative, start from abs(start) characters from the end of the buffer.
> - If no length is specified, continue to the end of the string.
> - BYTE_SUBSTR always assumes a character is 8 bits, while SUBSTR accounts for UTF-8 character sequences.
> - If the substring expression's length exceeds the value's upward bound, the
> value's length will be used.
> - If the substring is invalid (e.g. negative length), return an empty string.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira