stalary commented on code in PR #16806:
URL: https://github.com/apache/doris/pull/16806#discussion_r1111256623
##########
fe/fe-core/src/test/java/org/apache/doris/external/elasticsearch/QueryBuildersTest.java:
##########
@@ -37,41 +61,174 @@ public class QueryBuildersTest {
private final ObjectMapper mapper = new ObjectMapper();
+ @Test
+ public void testBinaryPredicateConvertEsDsl() {
+ SlotRef k1 = new SlotRef(null, "k1");
+ IntLiteral intLiteral = new IntLiteral(3);
+ Expr eqExpr = new BinaryPredicate(Operator.EQ, k1, intLiteral);
+ Expr neExpr = new BinaryPredicate(Operator.NE, k1, intLiteral);
+ Expr leExpr = new BinaryPredicate(Operator.LE, k1, intLiteral);
+ Expr geExpr = new BinaryPredicate(Operator.GE, k1, intLiteral);
+ Expr ltExpr = new BinaryPredicate(Operator.LT, k1, intLiteral);
+ Expr gtExpr = new BinaryPredicate(Operator.GT, k1, intLiteral);
+ Expr efnExpr = new BinaryPredicate(Operator.EQ_FOR_NULL, new
SlotRef(null, "k1"), new IntLiteral(3));
+ Assertions.assertEquals("{\"term\":{\"k1\":3}}",
QueryBuilders.toEsDsl(eqExpr).toJson());
+
Assertions.assertEquals("{\"bool\":{\"must_not\":{\"term\":{\"k1\":3}}}}",
+ QueryBuilders.toEsDsl(neExpr).toJson());
+ Assertions.assertEquals("{\"range\":{\"k1\":{\"lte\":3}}}",
QueryBuilders.toEsDsl(leExpr).toJson());
+ Assertions.assertEquals("{\"range\":{\"k1\":{\"gte\":3}}}",
QueryBuilders.toEsDsl(geExpr).toJson());
+ Assertions.assertEquals("{\"range\":{\"k1\":{\"lt\":3}}}",
QueryBuilders.toEsDsl(ltExpr).toJson());
+ Assertions.assertEquals("{\"range\":{\"k1\":{\"gt\":3}}}",
QueryBuilders.toEsDsl(gtExpr).toJson());
+ Assertions.assertEquals("{\"term\":{\"k1\":3}}",
QueryBuilders.toEsDsl(efnExpr).toJson());
+
+ SlotRef k2 = new SlotRef(null, "k2");
+ Expr dateTimeLiteral = new StringLiteral("2023-02-19 22:00:00");
+ Expr dateTimeEqExpr = new BinaryPredicate(Operator.EQ, k2,
dateTimeLiteral);
+ Map<String, ObjectNode> originMap = new HashMap<>();
+ Map<String, String> typeMap = new HashMap<>();
+ typeMap.put("type", "date");
+ originMap.put("k2", (ObjectNode) JsonUtil.toJsonNode(typeMap));
+
Assertions.assertEquals("{\"term\":{\"k2\":\"2023-02-19T22:00:00.000+08:00\"}}",
Review Comment:
`2023-02-19 22:00:00` transform to `2023-02-19T22:00:00.000+08:00`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]