@@ -3213,6 +3213,94 @@ public static Expression roundToPrecision(String numericField, Expression decima
32133213 return roundToPrecision (field (numericField ), decimalPlace );
32143214 }
32153215
3216+ /**
3217+ * Creates an expression that returns a random double between 0.0 and 1.0 but not including 1.0.
3218+ *
3219+ * @return A new {@link Expression} representing a random double result from the rand operation.
3220+ */
3221+ @ BetaApi
3222+ public static Expression rand () {
3223+ return new FunctionExpression ("rand" , ImmutableList .of ());
3224+ }
3225+
3226+ /**
3227+ * Creates an expression that truncates {@code numericExpr} to an integer.
3228+ *
3229+ * @param numericExpr An expression that returns number when evaluated.
3230+ * @return A new {@link Expression} representing the trunc operation.
3231+ */
3232+ @ BetaApi
3233+ public static Expression trunc (Expression numericExpr ) {
3234+ return new FunctionExpression ("trunc" , ImmutableList .of (numericExpr ));
3235+ }
3236+
3237+ /**
3238+ * Creates an expression that truncates {@code numericField} to an integer.
3239+ *
3240+ * @param numericField Name of field that returns number when evaluated.
3241+ * @return A new {@link Expression} representing the trunc operation.
3242+ */
3243+ @ BetaApi
3244+ public static Expression trunc (String numericField ) {
3245+ return trunc (field (numericField ));
3246+ }
3247+
3248+ /**
3249+ * Creates an expression that truncates {@code numericExpr} to {@code decimalPlace} decimal places
3250+ * if {@code decimalPlace} is positive, truncates digits to the left of the decimal point if
3251+ * {@code decimalPlace} is negative.
3252+ *
3253+ * @param numericExpr An expression that returns number when evaluated.
3254+ * @param decimalPlace The number of decimal places to truncate.
3255+ * @return A new {@link Expression} representing the trunc operation.
3256+ */
3257+ @ BetaApi
3258+ public static Expression truncToPrecision (Expression numericExpr , int decimalPlace ) {
3259+ return new FunctionExpression ("trunc" , ImmutableList .of (numericExpr , constant (decimalPlace )));
3260+ }
3261+
3262+ /**
3263+ * Creates an expression that truncates {@code numericField} to {@code decimalPlace} decimal
3264+ * places if {@code decimalPlace} is positive, truncates digits to the left of the decimal point
3265+ * if {@code decimalPlace} is negative.
3266+ *
3267+ * @param numericField Name of field that returns number when evaluated.
3268+ * @param decimalPlace The number of decimal places to truncate.
3269+ * @return A new {@link Expression} representing the trunc operation.
3270+ */
3271+ @ BetaApi
3272+ public static Expression truncToPrecision (String numericField , int decimalPlace ) {
3273+ return truncToPrecision (field (numericField ), decimalPlace );
3274+ }
3275+
3276+ /**
3277+ * Creates an expression that truncates {@code numericExpr} to {@code decimalPlace} decimal places
3278+ * if {@code decimalPlace} is positive, truncates digits to the left of the decimal point if
3279+ * {@code decimalPlace} is negative.
3280+ *
3281+ * @param numericExpr An expression that returns number when evaluated.
3282+ * @param decimalPlace The number of decimal places to truncate.
3283+ * @return A new {@link Expression} representing the trunc operation.
3284+ */
3285+ @ BetaApi
3286+ public static Expression truncToPrecision (Expression numericExpr , Expression decimalPlace ) {
3287+ return new FunctionExpression ("trunc" , ImmutableList .of (numericExpr , decimalPlace ));
3288+ }
3289+
3290+ /**
3291+ * Creates an expression that truncates {@code numericField} to {@code decimalPlace} decimal
3292+ * places if {@code decimalPlace} is positive, truncates digits to the left of the decimal point
3293+ * if {@code decimalPlace} is negative.
3294+ *
3295+ * @param numericField Name of field that returns number when evaluated.
3296+ * @param decimalPlace The number of decimal places to truncate.
3297+ * @return A new {@link Expression} representing the trunc operation.
3298+ */
3299+ @ BetaApi
3300+ public static Expression truncToPrecision (String numericField , Expression decimalPlace ) {
3301+ return truncToPrecision (field (numericField ), decimalPlace );
3302+ }
3303+
32163304 /**
32173305 * Creates an expression that returns the smallest integer that isn't less than {@code
32183306 * numericExpr}.
@@ -3686,6 +3774,42 @@ public final Expression roundToPrecision(Expression decimalPlace) {
36863774 return roundToPrecision (this , decimalPlace );
36873775 }
36883776
3777+ /**
3778+ * Creates an expression that truncates this numeric expression to an integer.
3779+ *
3780+ * @return A new {@link Expression} representing the trunc operation.
3781+ */
3782+ @ BetaApi
3783+ public final Expression trunc () {
3784+ return trunc (this );
3785+ }
3786+
3787+ /**
3788+ * Creates an expression that truncates this numeric expression to {@code decimalPlace} decimal
3789+ * places if {@code decimalPlace} is positive, truncates digits to the left of the decimal point
3790+ * if {@code decimalPlace} is negative.
3791+ *
3792+ * @param decimalPlace The number of decimal places to truncate.
3793+ * @return A new {@link Expression} representing the trunc operation.
3794+ */
3795+ @ BetaApi
3796+ public final Expression truncToPrecision (int decimalPlace ) {
3797+ return truncToPrecision (this , decimalPlace );
3798+ }
3799+
3800+ /**
3801+ * Creates an expression that truncates this numeric expression to {@code decimalPlace} decimal
3802+ * places if {@code decimalPlace} is positive, truncates digits to the left of the decimal point
3803+ * if {@code decimalPlace} is negative.
3804+ *
3805+ * @param decimalPlace The number of decimal places to truncate.
3806+ * @return A new {@link Expression} representing the trunc operation.
3807+ */
3808+ @ BetaApi
3809+ public final Expression truncToPrecision (Expression decimalPlace ) {
3810+ return truncToPrecision (this , decimalPlace );
3811+ }
3812+
36893813 /**
36903814 * Creates an expression that returns the smallest integer that isn't less than this numeric
36913815 * expression.
0 commit comments