Class CaseExpr


  • public class CaseExpr
    extends Column
    Represents a CASE expression.

    To construct this object for a CASE expression, call the com.snowflake.snowpark_java.Functions.when. specifying a condition and the corresponding result for that condition. Then, call the when and otherwise methods to specify additional conditions and results.

    Since:
    0.12.0
    • Method Detail

      • when

        public CaseExpr when​(Column condition,
                             java.lang.Object value)
        Appends one more WHEN condition to the CASE expression. This method handles any literal value and converts it into a `Column` if applies.

        Example:

        
         Column result = when(col("age").lt(lit(18)), "Minor")
         .when(col("age").lt(lit(65)), "Adult")
         .otherwise("Senior");
         
        Parameters:
        condition - The case condition
        value - The result value in the given condition
        Returns:
        The result case expression
        Since:
        0.12.0
      • otherwise

        public Column otherwise​(java.lang.Object value)
        Sets the default result for this CASE expression. This method handles any literal value and converts it into a `Column` if applies.

        Example:

        
         Column result = when(col("state").equal(lit("CA")), lit(1000))
         .when(col("state").equal(lit("NY")), lit(2000))
         .otherwise(1000);
         
        Parameters:
        value - The default value, which can be any literal (e.g., String, int, boolean) or a `Column`.
        Returns:
        The result column.
        Since:
        0.12.0