aws-sdk-java icon indicating copy to clipboard operation
aws-sdk-java copied to clipboard

list_append does not accept FunctionOperand

Open vitaliysapounov opened this issue 2 years ago • 3 comments

Describe the bug

We tried to append an element to a List attribute in DynamoDB by executing an update like (https://stackoverflow.com/a/35001736):

SET my_list2 = list_append(if_not_exists(my_list2, :empty_list), :my_value)

Note that if_not_exists() is needed, as if the attribute does not yet exist, simply list_append(my_list2, :my_value) produces an error "The provided expression refers to an attribute that does not exist in the item".

However, in ExpressionSpecBuilder.java the following method defined:

    public static <T> ListAppendFunction list_append(String path,
            List<? extends T> value) {
        return new ListAppendFunction(L(path), new ListLiteralOperand(new LinkedList<T>(
                value)));
    }

Note that the first operand requires a path (String), but in our case we need to pass FunctionOperand (that ExpressionSpecBuilder.if_not_exists() returns). Another method needs to be introduced with a signature like:

    public static <T> ListAppendFunction list_append(FunctionOperand expression, List<? extends T> value)

or even just

    public static <T> ListAppendFunction list_append(Operand expression, List<? extends T> value)

Expected Behavior

ExpressionSpecBuilder.list_append() accepts FunctionOperand (or just Operand) as the first argument

Current Behavior

ExpressionSpecBuilder.list_append() accepts String (attribute path) only as the first argument

Reproduction Steps

package com.awsbug;

import java.util.Collections;

import static com.amazonaws.services.dynamodbv2.xspec.ExpressionSpecBuilder.L;
import static com.amazonaws.services.dynamodbv2.xspec.ExpressionSpecBuilder.list_append;

public class AwsBug {

    public static void main(String[] args) {
        return L("myAttr").set(
                list_append(
                        L("myAttr").ifNotExists(Collections.emptyList()),
                        "someStringLiteral"
                )
        );
    }
}

The above class does not compile.

Possible Solution

No response

Additional Information/Context

No response

AWS Java SDK version used

1.12.221

JDK version used

openjdk version "11.0.16" 2022-07-19 LTS OpenJDK Runtime Environment Corretto-11.0.16.8.1 (build 11.0.16+8-LTS) OpenJDK 64-Bit Server VM Corretto-11.0.16.8.1 (build 11.0.16+8-LTS, mixed mode)

Operating System and version

buntu 22.04.2 LTS

vitaliysapounov avatar Jun 23 '23 18:06 vitaliysapounov

@vitaliysapounov makes sense. Thank you for reporting.

Just a heads-up, the focus of the team is in Java SDK 2.x features, so this has a low chance to be implemented in 1.x. ExpressionSpecBuilder is not supported in Java SDK 2.x, we are tracking here - https://github.com/aws/aws-sdk-java-v2/issues/2995.

debora-ito avatar Jul 24 '23 18:07 debora-ito

@debora-ito Thanks for answering! If I provide a pull request, will it be of any help?

vitaliysapounov avatar Jul 24 '23 19:07 vitaliysapounov

A little, but not significantly, unfortunately. Java SDK 1.x mainline is in our internal systems, so we'd need to replicate the changes of the PR internally, and do the code review and perform tests. This would have low priority if compared to other tasks we need to work on.

We appreciate your interest in writing the PR.

debora-ito avatar Jul 24 '23 20:07 debora-ito

@vitaliysapounov this will not get fixed in v1 before going into Maintenance Mode, so I'll go ahead and close.

Expression builders are not available in v2 yet, you can track progress in this feature request: https://github.com/aws/aws-sdk-java-v2/issues/2995

Reference:

  • Announcing end-of-support for AWS SDK for Java v1.x effective December 31, 2025 - blog post

debora-ito avatar Jun 20 '24 02:06 debora-ito

This issue is now closed.

Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Jun 20 '24 02:06 github-actions[bot]