diff --git a/src/main/java/com/aerospike/dsl/parts/cdt/list/ListValue.java b/src/main/java/com/aerospike/dsl/parts/cdt/list/ListValue.java index ed5064b..488a788 100644 --- a/src/main/java/com/aerospike/dsl/parts/cdt/list/ListValue.java +++ b/src/main/java/com/aerospike/dsl/parts/cdt/list/ListValue.java @@ -7,6 +7,7 @@ import com.aerospike.dsl.client.exp.ListExp; import com.aerospike.dsl.parts.path.BasePath; +import static com.aerospike.dsl.util.ParsingUtils.objectToExp; import static com.aerospike.dsl.util.ParsingUtils.parseValueIdentifier; public class ListValue extends ListPart { @@ -23,13 +24,7 @@ public static ListValue from(ConditionParser.ListValueContext ctx) { @Override public Exp constructExp(BasePath basePath, Exp.Type valueType, int cdtReturnType, CTX[] context) { - Exp valueExp = switch (valueType) { - case BOOL -> Exp.val((Boolean) value); - case STRING -> Exp.val((String) value); - case FLOAT -> Exp.val((Float) value); - default -> Exp.val((Integer) value); // for getByValue the default is INT - }; - return ListExp.getByValue(cdtReturnType, valueExp, Exp.bin(basePath.getBinPart().getBinName(), + return ListExp.getByValue(cdtReturnType, objectToExp(value), Exp.bin(basePath.getBinPart().getBinName(), basePath.getBinType()), context); } diff --git a/src/main/java/com/aerospike/dsl/parts/cdt/map/MapValue.java b/src/main/java/com/aerospike/dsl/parts/cdt/map/MapValue.java index 2cf1bdc..4d78fbc 100644 --- a/src/main/java/com/aerospike/dsl/parts/cdt/map/MapValue.java +++ b/src/main/java/com/aerospike/dsl/parts/cdt/map/MapValue.java @@ -7,6 +7,7 @@ import com.aerospike.dsl.client.exp.MapExp; import com.aerospike.dsl.parts.path.BasePath; +import static com.aerospike.dsl.util.ParsingUtils.objectToExp; import static com.aerospike.dsl.util.ParsingUtils.parseValueIdentifier; public class MapValue extends MapPart { @@ -23,14 +24,7 @@ public static MapValue from(ConditionParser.MapValueContext ctx) { @Override public Exp constructExp(BasePath basePath, Exp.Type valueType, int cdtReturnType, CTX[] context) { - Exp valueExp = switch (valueType) { - case BOOL -> Exp.val((Boolean) value); - case STRING -> Exp.val((String) value); - case FLOAT -> Exp.val((Float) value); - default -> Exp.val((Integer) value); // for getByValue the default is INT - }; - - return MapExp.getByValue(cdtReturnType, valueExp, Exp.bin(basePath.getBinPart().getBinName(), + return MapExp.getByValue(cdtReturnType, objectToExp(value), Exp.bin(basePath.getBinPart().getBinName(), basePath.getBinType()), context); } diff --git a/src/main/java/com/aerospike/dsl/parts/path/Path.java b/src/main/java/com/aerospike/dsl/parts/path/Path.java index 744c2e3..94f5722 100644 --- a/src/main/java/com/aerospike/dsl/parts/path/Path.java +++ b/src/main/java/com/aerospike/dsl/parts/path/Path.java @@ -35,12 +35,15 @@ public Exp processPath(BasePath basePath, PathFunction pathFunction) { cdtReturnType = ((CdtPart) lastPathPart).getReturnType(pathFunction.getReturnParam()); } - if (lastPathPart != null) { // only if there are other parts except a bin - return switch (pathFunction.getPathFunctionType()) { - // CAST is the same as GET with a different type + if (lastPathPart != null) { + Exp exp = switch (pathFunction.getPathFunctionType()) { case GET, COUNT, CAST -> processGet(basePath, lastPathPart, valueType, cdtReturnType); case SIZE -> processSize(basePath, lastPathPart, valueType, cdtReturnType); }; + if (pathFunction.getPathFunctionType() == PathFunction.PathFunctionType.CAST && exp != null) { + exp = pathFunction.getBinType() == Exp.Type.FLOAT ? Exp.toFloat(exp) : Exp.toInt(exp); + } + return exp; } return null; } diff --git a/src/main/java/com/aerospike/dsl/parts/path/PathFunction.java b/src/main/java/com/aerospike/dsl/parts/path/PathFunction.java index 47e34d8..2775095 100644 --- a/src/main/java/com/aerospike/dsl/parts/path/PathFunction.java +++ b/src/main/java/com/aerospike/dsl/parts/path/PathFunction.java @@ -2,6 +2,7 @@ import com.aerospike.dsl.client.exp.Exp; import com.aerospike.dsl.parts.AbstractPart; +import com.aerospike.dsl.parts.ExpressionContainer.ExprPartsOperation; import lombok.Getter; @Getter @@ -25,6 +26,24 @@ public static Exp.Type castTypeToExpType(CastType castType) { }; } + /** + * Returns the source {@link Exp.Type} for a cast — the type the value must + * already have before the cast is applied (e.g., casting to INT requires a FLOAT source). + */ + public static Exp.Type castSourceExpType(CastType castType) { + return switch (castType) { + case INT -> Exp.Type.FLOAT; + case FLOAT -> Exp.Type.INT; + }; + } + + public static ExprPartsOperation castTypeToOperation(CastType castType) { + return switch (castType) { + case INT -> ExprPartsOperation.TO_INT; + case FLOAT -> ExprPartsOperation.TO_FLOAT; + }; + } + public enum ReturnParam { VALUE, INDEX, diff --git a/src/main/java/com/aerospike/dsl/util/ParsingUtils.java b/src/main/java/com/aerospike/dsl/util/ParsingUtils.java index ef75653..c7a0234 100644 --- a/src/main/java/com/aerospike/dsl/util/ParsingUtils.java +++ b/src/main/java/com/aerospike/dsl/util/ParsingUtils.java @@ -2,6 +2,7 @@ import com.aerospike.dsl.ConditionParser; import com.aerospike.dsl.DslParseException; +import com.aerospike.dsl.client.exp.Exp; import lombok.NonNull; import lombok.experimental.UtilityClass; import org.antlr.v4.runtime.ParserRuleContext; @@ -166,6 +167,21 @@ public static Integer requireIntValueIdentifier(ConditionParser.ValueIdentifierC "Value range requires integer operands, got: %s".formatted(ctx.getText())); } + /** + * Converts a parsed value object to an {@link Exp} value expression. + * Supports the types produced by {@link #parseValueIdentifier}: {@link String} and {@link Integer}. + * + * @param value The parsed value object + * @return The corresponding {@link Exp} value expression + * @throws DslParseException if the value type is not supported + */ + public static Exp objectToExp(Object value) { + if (value instanceof String s) return Exp.val(s); + if (value instanceof Integer i) return Exp.val(i); + throw new DslParseException( + "Unsupported value type for Exp conversion: " + value.getClass().getSimpleName()); + } + /** * Get the string inside the quotes. * diff --git a/src/main/java/com/aerospike/dsl/util/PathOperandUtils.java b/src/main/java/com/aerospike/dsl/util/PathOperandUtils.java index a6179f8..8cac60c 100644 --- a/src/main/java/com/aerospike/dsl/util/PathOperandUtils.java +++ b/src/main/java/com/aerospike/dsl/util/PathOperandUtils.java @@ -39,7 +39,6 @@ public class PathOperandUtils { * @return The determined {@link Exp.Type} for the value */ public static Exp.Type processValueType(AbstractPart lastPathPart, PathFunction pathFunction) { - // there is always a path function with non-null function type and return param if (pathFunction.getBinType() == null) { if (isListTypeDesignator(lastPathPart)) { return Exp.Type.LIST; @@ -49,6 +48,16 @@ public static Exp.Type processValueType(AbstractPart lastPathPart, PathFunction return findValueType(lastPathPart, pathFunction.getPathFunctionType()); } } + if (pathFunction.getPathFunctionType() == PathFunction.PathFunctionType.CAST) { + // Value selectors (getByValue/getByValueList/getByValueRange) have no return-type + // parameter; their constructExp ignores valueType. The cast wrapping is applied + // afterward in Path.processPath(), so the source-type logic does not apply here. + if (isValueSelector(lastPathPart)) { + return TypeUtils.getDefaultType(lastPathPart); + } + PathFunction.CastType castType = PathFunction.CastType.valueOf(pathFunction.getBinType().toString()); + return PathFunction.castSourceExpType(castType); + } return Exp.Type.valueOf(pathFunction.getBinType().toString()); } @@ -226,6 +235,20 @@ private static boolean isMapTypeDesignator(AbstractPart cdtPart) { return cdtPart.getPartType() == MAP_PART && ((MapPart) cdtPart).getMapPartType().equals(MAP_TYPE_DESIGNATOR); } + private static boolean isValueSelector(AbstractPart cdtPart) { + if (cdtPart.getPartType() == LIST_PART) { + ListPart.ListPartType type = ((ListPart) cdtPart).getListPartType(); + return type == ListPart.ListPartType.VALUE || type == ListPart.ListPartType.VALUE_LIST + || type == ListPart.ListPartType.VALUE_RANGE; + } + if (cdtPart.getPartType() == MAP_PART) { + MapPart.MapPartType type = ((MapPart) cdtPart).getMapPartType(); + return type == MapPart.MapPartType.VALUE || type == MapPart.MapPartType.VALUE_LIST + || type == MapPart.MapPartType.VALUE_RANGE; + } + return false; + } + /** * Constructs an array of {@link CTX} (context) objects from a list of {@link AbstractPart} objects. * This is used to build the context for nested CDT operations. diff --git a/src/main/java/com/aerospike/dsl/visitor/ExpressionConditionVisitor.java b/src/main/java/com/aerospike/dsl/visitor/ExpressionConditionVisitor.java index 18fa267..9dde00a 100644 --- a/src/main/java/com/aerospike/dsl/visitor/ExpressionConditionVisitor.java +++ b/src/main/java/com/aerospike/dsl/visitor/ExpressionConditionVisitor.java @@ -1013,30 +1013,39 @@ public AbstractPart visitVariable(ConditionParser.VariableContext ctx) { @Override public AbstractPart visitPath(ConditionParser.PathContext ctx) { BasePath basePath = (BasePath) visit(ctx.basePath()); - List cdtParts = basePath.getCdtParts(); - overrideWithPathFunction(basePath.getBinPart(), ctx); - - // if there are other parts except bin, get a corresponding Exp - if (!cdtParts.isEmpty() || ctx.pathFunction() != null && ctx.pathFunction().pathFunctionCount() != null) { - return new Path(basePath, ctx.pathFunction() == null - ? null - : (PathFunction) visit(ctx.pathFunction())); + PathFunction pathFunction = visitPathFunctionIfPresent(ctx); + + if (!basePath.getCdtParts().isEmpty() + || pathFunction != null && pathFunction.getPathFunctionType() == PathFunction.PathFunctionType.COUNT) { + return new Path(basePath, pathFunction); + } + + if (pathFunction != null && pathFunction.getPathFunctionType() == PathFunction.PathFunctionType.CAST) { + return buildBinCast(basePath.getBinPart(), pathFunction); } + + overrideBinWithPathFunction(basePath.getBinPart(), pathFunction); return basePath.getBinPart(); } - private void overrideWithPathFunction(BinPart binPart, ConditionParser.PathContext ctx) { - ConditionParser.PathFunctionContext pathFunctionContext = ctx.pathFunction(); + private PathFunction visitPathFunctionIfPresent(ConditionParser.PathContext ctx) { + return ctx.pathFunction() != null ? (PathFunction) visit(ctx.pathFunction()) : null; + } - // Override with path function (explicit get or cast) - if (pathFunctionContext != null) { - PathFunction pathFunction = (PathFunction) visit(pathFunctionContext); - if (pathFunction != null) { - Exp.Type type = pathFunction.getBinType(); - if (type != null) { - binPart.updateExp(type); - binPart.setTypeExplicitlySet(true); - } + private AbstractPart buildBinCast(BinPart binPart, PathFunction pathFunction) { + String castText = pathFunction.getBinType().toString(); + PathFunction.CastType castType = PathFunction.CastType.valueOf(castText); + binPart.updateExp(PathFunction.castSourceExpType(castType)); + binPart.setTypeExplicitlySet(true); + return new ExpressionContainer(binPart, PathFunction.castTypeToOperation(castType)); + } + + private void overrideBinWithPathFunction(BinPart binPart, PathFunction pathFunction) { + if (pathFunction != null) { + Exp.Type type = pathFunction.getBinType(); + if (type != null) { + binPart.updateExp(type); + binPart.setTypeExplicitlySet(true); } } } diff --git a/src/main/java/com/aerospike/dsl/visitor/VisitorUtils.java b/src/main/java/com/aerospike/dsl/visitor/VisitorUtils.java index 07ab640..fe56f5b 100644 --- a/src/main/java/com/aerospike/dsl/visitor/VisitorUtils.java +++ b/src/main/java/com/aerospike/dsl/visitor/VisitorUtils.java @@ -353,9 +353,14 @@ private static Exp getExpBinComparison(BinPart binPart, AbstractPart anotherPart binExp = Exp.bin(binPart.getBinName(), binType); yield anotherPart.getExp(); } - case EXPRESSION_CONTAINER, PATH_OPERAND, VARIABLE_OPERAND -> - // Can't validate with expression container - anotherPart.getExp(); + case EXPRESSION_CONTAINER -> { + Exp.Type resolvedType = resolveExpType(anotherPart); + if (resolvedType != null) { + validateComparableTypes(binPart.getExpType(), resolvedType); + } + yield anotherPart.getExp(); + } + case PATH_OPERAND, VARIABLE_OPERAND -> anotherPart.getExp(); case BIN_PART -> { // Both are bin parts validateComparableTypes(binPart.getExpType(), anotherPart.getExpType()); diff --git a/src/test/java/com/aerospike/dsl/expression/CastingTests.java b/src/test/java/com/aerospike/dsl/expression/CastingTests.java index e0a9789..19fe9fb 100644 --- a/src/test/java/com/aerospike/dsl/expression/CastingTests.java +++ b/src/test/java/com/aerospike/dsl/expression/CastingTests.java @@ -2,8 +2,14 @@ import com.aerospike.dsl.DslParseException; import com.aerospike.dsl.ExpressionContext; +import com.aerospike.dsl.client.cdt.ListReturnType; +import com.aerospike.dsl.client.cdt.MapReturnType; import com.aerospike.dsl.client.exp.Exp; +import com.aerospike.dsl.client.exp.ListExp; +import com.aerospike.dsl.client.exp.MapExp; import com.aerospike.dsl.util.TestUtils; +import com.aerospike.dsl.client.cdt.CTX; +import com.aerospike.dsl.client.Value; import org.junit.jupiter.api.Test; import static com.aerospike.dsl.util.TestUtils.parseFilterExp; @@ -11,20 +17,6 @@ public class CastingTests { - @Test - void floatToIntComparison() { - Exp expectedExp = Exp.gt(Exp.intBin("intBin1"), Exp.intBin("floatBin1")); - // Int is default - TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.intBin1 > $.floatBin1.asInt()"), expectedExp); - TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.intBin1.get(type: INT) > $.floatBin1.asInt()"), expectedExp); - } - - @Test - void intToFloatComparison() { - TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.intBin1.get(type: INT) > $.intBin2.asFloat()"), - Exp.gt(Exp.intBin("intBin1"), Exp.floatBin("intBin2"))); - } - @Test void negativeInvalidTypesComparison() { assertThatThrownBy(() -> parseFilterExp(ExpressionContext.of("$.stringBin1.get(type: STRING) > $.intBin2.asFloat()"))) @@ -99,4 +91,166 @@ void castToIntComparedToStringThrows() { .isInstanceOf(DslParseException.class) .hasMessageContaining("Cannot compare"); } + + // --- Explicit bin casting (asFloat/asInt produce Exp.toFloat/toInt wrappers) --- + + @Test + void binAsFloat() { + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.bin.asFloat() == 1.0"), + Exp.eq(Exp.toFloat(Exp.intBin("bin")), Exp.val(1.0))); + } + + @Test + void binAsInt() { + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.bin.asInt() == 1"), + Exp.eq(Exp.toInt(Exp.floatBin("bin")), Exp.val(1))); + } + + @Test + void binAsIntInComparison() { + Exp expectedExp = Exp.gt(Exp.intBin("intBin1"), Exp.toInt(Exp.floatBin("floatBin1"))); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.intBin1 > $.floatBin1.asInt()"), expectedExp); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.intBin1.get(type: INT) > $.floatBin1.asInt()"), expectedExp); + } + + @Test + void binAsFloatInComparison() { + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.intBin1.get(type: INT) > $.intBin2.asFloat()"), + Exp.gt(Exp.intBin("intBin1"), Exp.toFloat(Exp.intBin("intBin2")))); + } + + @Test + void binAsFloatInAddition() { + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.binA.asFloat() + 4.0 == 5.0"), + Exp.eq(Exp.add(Exp.toFloat(Exp.intBin("binA")), Exp.val(4.0)), Exp.val(5.0))); + } + + @Test + void binAsIntInSubtraction() { + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.binA.asInt() - 3 == 0"), + Exp.eq(Exp.sub(Exp.toInt(Exp.floatBin("binA")), Exp.val(3)), Exp.val(0))); + } + + // --- CDT list casting --- + + @Test + void listIndexAsInt() { + Exp expected = Exp.eq( + Exp.toInt(ListExp.getByIndex(ListReturnType.VALUE, Exp.Type.FLOAT, + Exp.val(0), Exp.listBin("listBin1"))), + Exp.val(100)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[0].asInt() == 100"), expected); + } + + @Test + void listIndexAsFloat() { + Exp expected = Exp.eq( + Exp.toFloat(ListExp.getByIndex(ListReturnType.VALUE, Exp.Type.INT, + Exp.val(0), Exp.listBin("listBin1"))), + Exp.val(100.0)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[0].asFloat() == 100.0"), expected); + } + + @Test + void listValueAsInt() { + Exp expected = Exp.eq( + Exp.toInt(ListExp.getByValue(ListReturnType.VALUE, + Exp.val(100), Exp.listBin("listBin1"))), + Exp.val(100)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[=100].asInt() == 100"), expected); + } + + @Test + void listRankAsInt() { + Exp expected = Exp.eq( + Exp.toInt(ListExp.getByRank(ListReturnType.VALUE, Exp.Type.FLOAT, + Exp.val(-1), Exp.listBin("listBin1"))), + Exp.val(100)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[#-1].asInt() == 100"), expected); + } + + @Test + void listValueAsFloat() { + Exp expected = Exp.eq( + Exp.toFloat(ListExp.getByValue(ListReturnType.VALUE, + Exp.val(100), Exp.listBin("listBin1"))), + Exp.val(100.0)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[=100].asFloat() == 100.0"), expected); + } + + @Test + void listRankAsFloat() { + Exp expected = Exp.eq( + Exp.toFloat(ListExp.getByRank(ListReturnType.VALUE, Exp.Type.INT, + Exp.val(-1), Exp.listBin("listBin1"))), + Exp.val(100.0)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[#-1].asFloat() == 100.0"), expected); + } + + // --- CDT map casting --- + + @Test + void mapKeyAsInt() { + Exp expected = Exp.eq( + Exp.toInt(MapExp.getByKey(MapReturnType.VALUE, Exp.Type.FLOAT, + Exp.val("a"), Exp.mapBin("mapBin1"))), + Exp.val(200)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.a.asInt() == 200"), expected); + } + + @Test + void mapKeyAsFloat() { + Exp expected = Exp.eq( + Exp.toFloat(MapExp.getByKey(MapReturnType.VALUE, Exp.Type.INT, + Exp.val("a"), Exp.mapBin("mapBin1"))), + Exp.val(200.0)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.a.asFloat() == 200.0"), expected); + } + + @Test + void mapIndexAsInt() { + Exp expected = Exp.eq( + Exp.toInt(MapExp.getByIndex(MapReturnType.VALUE, Exp.Type.FLOAT, + Exp.val(0), Exp.mapBin("mapBin1"))), + Exp.val(100)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{0}.asInt() == 100"), expected); + } + + @Test + void mapIndexAsFloat() { + Exp expected = Exp.eq( + Exp.toFloat(MapExp.getByIndex(MapReturnType.VALUE, Exp.Type.INT, + Exp.val(0), Exp.mapBin("mapBin1"))), + Exp.val(100.0)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{0}.asFloat() == 100.0"), expected); + } + + @Test + void mapValueAsInt() { + Exp expected = Exp.eq( + Exp.toInt(MapExp.getByValue(MapReturnType.VALUE, + Exp.val(100), Exp.mapBin("mapBin1"))), + Exp.val(100)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{=100}.asInt() == 100"), expected); + } + + @Test + void mapRankAsInt() { + Exp expected = Exp.eq( + Exp.toInt(MapExp.getByRank(MapReturnType.VALUE, Exp.Type.FLOAT, + Exp.val(-1), Exp.mapBin("mapBin1"))), + Exp.val(100)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{#-1}.asInt() == 100"), expected); + } + + @Test + void nestedMapRankAsInt() { + Exp expected = Exp.eq( + Exp.toInt(MapExp.getByRank(MapReturnType.VALUE, Exp.Type.FLOAT, + Exp.val(-1), Exp.mapBin("mapBin1"), + CTX.mapKey(Value.get("a")))), + Exp.val(100)); + TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.a.{#-1}.asInt() == 100"), expected); + } + } diff --git a/src/test/java/com/aerospike/dsl/expression/InExplicitTypeTests.java b/src/test/java/com/aerospike/dsl/expression/InExplicitTypeTests.java index 49ddf34..081d315 100644 --- a/src/test/java/com/aerospike/dsl/expression/InExplicitTypeTests.java +++ b/src/test/java/com/aerospike/dsl/expression/InExplicitTypeTests.java @@ -191,7 +191,7 @@ void explicitMapBinInPath() { @Test void castIntBinInBin() { Exp expected = ListExp.getByValue(ListReturnType.EXISTS, - Exp.intBin("val"), Exp.listBin("list")); + Exp.toInt(Exp.floatBin("val")), Exp.listBin("list")); parseFilterExpressionAndCompare( ExpressionContext.of("$.val.asInt() in $.list"), expected); } @@ -199,7 +199,7 @@ void castIntBinInBin() { @Test void castFloatBinInBin() { Exp expected = ListExp.getByValue(ListReturnType.EXISTS, - Exp.floatBin("val"), Exp.listBin("list")); + Exp.toFloat(Exp.intBin("val")), Exp.listBin("list")); parseFilterExpressionAndCompare( ExpressionContext.of("$.val.asFloat() in $.list"), expected); } @@ -207,7 +207,7 @@ void castFloatBinInBin() { @Test void castIntBinInPath() { Exp expected = ListExp.getByValue(ListReturnType.EXISTS, - Exp.intBin("val"), + Exp.toInt(Exp.floatBin("val")), MapExp.getByKey(MapReturnType.VALUE, Exp.Type.STRING, Exp.val("tags"), Exp.mapBin("items"))); parseFilterExpressionAndCompare( @@ -217,7 +217,7 @@ void castIntBinInPath() { @Test void castFloatBinInPath() { Exp expected = ListExp.getByValue(ListReturnType.EXISTS, - Exp.floatBin("val"), + Exp.toFloat(Exp.intBin("val")), MapExp.getByKey(MapReturnType.VALUE, Exp.Type.STRING, Exp.val("tags"), Exp.mapBin("items"))); parseFilterExpressionAndCompare( diff --git a/src/test/java/com/aerospike/dsl/expression/ListExpressionsTests.java b/src/test/java/com/aerospike/dsl/expression/ListExpressionsTests.java index 14fc23c..a10498c 100644 --- a/src/test/java/com/aerospike/dsl/expression/ListExpressionsTests.java +++ b/src/test/java/com/aerospike/dsl/expression/ListExpressionsTests.java @@ -31,7 +31,6 @@ void listByIndexInteger() { TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[0].get(type: INT) == 100"), expected); TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[0].get(type: INT, return: VALUE) == 100"), expected); - TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[0].asInt() == 100"), expected); } @Test @@ -79,7 +78,6 @@ void listByValue() { TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[=100].get(type: INT) == 100"), expected); TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[=100].get(type: INT, return: VALUE) == 100"), expected); - TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[=100].asInt() == 100"), expected); } @Test @@ -136,7 +134,6 @@ void listByRank() { TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[#-1].get(type: INT) == 100"), expected); TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[#-1].get(type: INT, return: VALUE) == 100"), expected); - TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.listBin1.[#-1].asInt() == 100"), expected); } @Test diff --git a/src/test/java/com/aerospike/dsl/expression/MapExpressionsTests.java b/src/test/java/com/aerospike/dsl/expression/MapExpressionsTests.java index 5853d1e..6479088 100644 --- a/src/test/java/com/aerospike/dsl/expression/MapExpressionsTests.java +++ b/src/test/java/com/aerospike/dsl/expression/MapExpressionsTests.java @@ -35,7 +35,6 @@ void mapOneLevelExpressions() { TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.a.get(type: INT) == 200"), expected); TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.a.get(type: INT, return: VALUE) == 200"), expected); - TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.a.asInt() == 200"), expected); // String expected = Exp.eq( @@ -218,7 +217,6 @@ void mapByIndex() { TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{0}.get(type: INT) == 100"), expected); TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{0}.get(type: INT, return: VALUE) == 100"), expected); - TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{0}.asInt() == 100"), expected); Exp expected2 = Exp.eq( MapExp.getByIndex( @@ -247,7 +245,6 @@ void mapByValue() { TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{=100}.get(type: INT) == 100"), expected); TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{=100}.get(type: INT, return: VALUE) == 100"), expected); - TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{=100}.asInt() == 100"), expected); } @Test @@ -304,7 +301,6 @@ void mapByRank() { TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{#-1}.get(type: INT) == 100"), expected); TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{#-1}.get(type: INT, return: VALUE) == 100"), expected); - TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.{#-1}.asInt() == 100"), expected); } @Test @@ -351,7 +347,6 @@ void mapByRankWithNesting() { TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.a.{#-1}.get(type: INT) == 100"), expected); TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.a.{#-1}.get(type: INT, return: VALUE) == 100"), expected); - TestUtils.parseFilterExpressionAndCompare(ExpressionContext.of("$.mapBin1.a.{#-1}.asInt() == 100"), expected); } @Test