Class ProjectionExpression

java.lang.Object
dev.hogwai.dynamodb.simplified.expression.ProjectionExpression

public class ProjectionExpression extends Object
Fluent builder for constructing DynamoDB projection expressions as part of the DynamoDB Simplified library.

A projection expression specifies the attributes to retrieve from a DynamoDB table or index, reducing the data returned by Scan, Query, or GetItem operations. This builder automatically maps attribute names to expression attribute name placeholders (#p0, #p1, ...) to avoid reserved word conflicts. Supports top-level attributes, nested attribute paths (e.g., address.city), and list element access (e.g., items[0]).

  • Method Details

    • builder

      public static @NonNull ProjectionExpression builder()
      Creates a new ProjectionExpression builder.
      Returns:
      a new empty ProjectionExpression
    • include

      public @NonNull ProjectionExpression include(@NonNull String... attributes)
      Includes one or more top-level attribute names in the projection. Each attribute is automatically mapped to an expression attribute name placeholder.
      Parameters:
      attributes - one or more attribute names to include
      Returns:
      this builder for chaining
    • includeNested

      public @NonNull ProjectionExpression includeNested(@NonNull String path)
      Includes a nested attribute path in the projection (e.g. "address.city"). Each path segment is mapped to an expression attribute name placeholder.
      Parameters:
      path - the dotted nested attribute path
      Returns:
      this builder for chaining
    • includeListElement

      public @NonNull ProjectionExpression includeListElement(@NonNull String attribute, int index)
      Includes a specific list element in the projection (e.g. "items[0]).
      Parameters:
      attribute - the attribute name
      index - the zero-based element index
      Returns:
      this builder for chaining
    • getExpression

      public @NonNull String getExpression()
      Returns the built projection expression string, a comma-separated list of attribute references (e.g., "#p0, #p1, #p2[0]").
      Returns:
      the projection expression string
    • getExpressionNames

      public @NonNull Map<String,String> getExpressionNames()
      Returns the map of expression attribute names used in this expression. Keys are the generated placeholders (e.g., #p0) and values are the original attribute names.
      Returns:
      the expression attribute names map
    • isEmpty

      public boolean isEmpty()
      Returns whether no attributes have been added to this projection yet.
      Returns:
      true if the projection is empty, false otherwise
    • getProjectedAttributes

      public @NonNull List<String> getProjectedAttributes()
      Returns the raw attribute paths as they were added by the user.

      These are the original attribute names and paths (e.g., "address.city") rather than the expression placeholder forms (e.g., "#p0.#p1"). Use this when passing projection attributes directly to the DynamoDB SDK's attributesToProject method.

      Returns:
      list of raw attribute paths