[ 
https://issues.apache.org/jira/browse/PHOENIX-1705?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14389890#comment-14389890
 ] 

James Taylor commented on PHOENIX-1705:
---------------------------------------

Thanks for the revisions, [~Dumindux]. Below is some feedback. In general, you 
shouldn't need any specific checks against a particular PDataType instance in 
your code, so remove all these.
- In ArrayAppendFunction constructor, it should look like this:
{code}
+    public ArrayAppendFunction(List<Expression> children) throws 
TypeMismatchException {
+        super(children);
+
+        if (!getElementDataType().isCoercibleTo(getBaseType())) {
+            throw TypeMismatchException.newException(getBaseType(), 
getElementDataType());
+        }
+
+        // If the base type of an element is fixed width, make sure the 
element being appended will fit
+        if (getBaseType().isFixedWidth() && getArrayExpr().getMaxLength() != 
null &&
+            getElementExpr().getMaxLength() != null && 
getElementExpr().getMaxLength() > getArrayExpr().getMaxLength()) {
+            throw new DataExceedsCapacityException();
+        }
+        // If the base type has a scale, make sure the element being appended 
has a scale less than or equal to it
+        if (getArrayExpr().getScale() != null && getElementExpr().getScale() 
!= null &&
+            getElementExpr().getScale() > getArrayExpr().getScale()) {
+            throw new DataExceedsCapacityException(getBaseType(), 
getArrayExpr().getMaxLength(), getArrayExpr().getScale());
+        }
+    }
+
{code}
- the evaluate method should look like this (you've got the wrong arguments to 
isSizeCompatible - take a look at example callers of that if you're not sure 
next time):
{code}
+    @Override
+    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+
+        if (!getArrayExpr().evaluate(tuple, ptr)) {
+            return false;
+        } else if (ptr.getLength() == 0) {
+            return true;
+        }
+        int arrayLength = PArrayDataType.getArrayLength(ptr, getBaseType(), 
getArrayExpr().getMaxLength());
+
+        int length = ptr.getLength();
+        int offset = ptr.getOffset();
+        byte[] arrayBytes = ptr.get();
+
+        if (!getElementExpr().evaluate(tuple, ptr) || ptr.getLength() == 0) {
+            ptr.set(arrayBytes, offset, length);
+            return true;
+        }
+        // See if actual value for the element being appended will fit into 
the array given its constraints
+        if (!getBaseType().isSizeCompatible(ptr, null, getElementDataType(),  
getElementExpr().getMaxLength(), getElementExpr().getScale(), 
getArrayExpr().getMaxLength(), getArrayExpr().getScale()) {
+            throw new DataExceedsCapacityException();
+        }
+
+        getBaseType().coerceBytes(ptr, getElementDataType(), 
getElementExpr().getSortOrder(), getArrayExpr().getSortOrder(), getMaxLength());
+
+        return PArrayDataType.appendItemToArray(ptr, length, offset, 
arrayBytes, getBaseType(), arrayLength, getMaxLength());
{code}
- Check what the default error message is for DataExceedsCapacityException and 
if it's reasonable, then don't include a specific error message in your 
constructor for it.


> implement ARRAY_APPEND built in function
> ----------------------------------------
>
>                 Key: PHOENIX-1705
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1705
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: Dumindu Buddhika
>            Assignee: Dumindu Buddhika
>         Attachments: 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function.patch, 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function.patch, 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function1.patch, 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function10.patch, 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function2.patch, 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function3.patch, 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function4.patch, 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function5.patch, 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function6.patch, 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function7.patch, 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function8.patch, 
> PHOENIX-1705_implement_ARRAY_APPEND_built_in_function9.patch
>
>




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to