|
10 | 10 | package net.sf.jsqlparser.expression.operators.relational; |
11 | 11 |
|
12 | 12 | import net.sf.jsqlparser.JSQLParserException; |
13 | | -import net.sf.jsqlparser.expression.BinaryExpression; |
14 | | -import net.sf.jsqlparser.expression.operators.arithmetic.Addition; |
15 | | -import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd; |
16 | 13 | import net.sf.jsqlparser.parser.CCJSqlParserUtil; |
17 | 14 | import net.sf.jsqlparser.test.TestUtils; |
18 | 15 | import org.junit.jupiter.api.Assertions; |
19 | 16 | import org.junit.jupiter.api.Test; |
20 | | -import org.junit.jupiter.params.ParameterizedTest; |
21 | | -import org.junit.jupiter.params.provider.ValueSource; |
22 | 17 |
|
23 | 18 |
|
24 | 19 | class ComparisonOperatorTest { |
@@ -48,95 +43,4 @@ void testCosineSimilarity() throws JSQLParserException { |
48 | 43 | Assertions.assertInstanceOf(CosineSimilarity.class, |
49 | 44 | CCJSqlParserUtil.parseExpression("embedding <=> '[3,1,2]'")); |
50 | 45 | } |
51 | | - |
52 | | - @Test |
53 | | - void testVectorDistanceOperatorsInProjection() throws JSQLParserException { |
54 | | - TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT a <-> b FROM t"); |
55 | | - TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT a <#> b FROM t"); |
56 | | - TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT a <=> b FROM t"); |
57 | | - Assertions.assertInstanceOf(GeometryDistance.class, |
58 | | - CCJSqlParserUtil.parseExpression("a <-> b")); |
59 | | - Assertions.assertInstanceOf(GeometryDistance.class, |
60 | | - CCJSqlParserUtil.parseExpression("a <#> b")); |
61 | | - Assertions.assertInstanceOf(CosineSimilarity.class, |
62 | | - CCJSqlParserUtil.parseExpression("a <=> b")); |
63 | | - } |
64 | | - |
65 | | - @ParameterizedTest |
66 | | - @ValueSource(strings = {"<->", "<#>", "<=>"}) |
67 | | - void testVectorDistanceOperatorsFollowedByComparison(String distance) |
68 | | - throws JSQLParserException { |
69 | | - String[] comparators = {"<", ">", "="}; |
70 | | - for (String comparator : comparators) { |
71 | | - TestUtils.assertSqlCanBeParsedAndDeparsed( |
72 | | - "SELECT * FROM t WHERE a " + distance + " b " + comparator + " c"); |
73 | | - TestUtils.assertSqlCanBeParsedAndDeparsed( |
74 | | - "SELECT * FROM t WHERE (a " + distance + " b) " + comparator + " c"); |
75 | | - } |
76 | | - Assertions.assertInstanceOf(MinorThan.class, |
77 | | - CCJSqlParserUtil.parseExpression("a " + distance + " b < c")); |
78 | | - } |
79 | | - |
80 | | - @ParameterizedTest |
81 | | - @ValueSource(strings = {"<->", "<#>", "<=>"}) |
82 | | - void testVectorDistanceOperatorsInProjectionFollowedByComparison(String distance) |
83 | | - throws JSQLParserException { |
84 | | - String[] comparators = {"<", ">", "="}; |
85 | | - for (String comparator : comparators) { |
86 | | - TestUtils.assertSqlCanBeParsedAndDeparsed( |
87 | | - "SELECT a " + distance + " b " + comparator + " c FROM t"); |
88 | | - TestUtils.assertSqlCanBeParsedAndDeparsed( |
89 | | - "SELECT (a " + distance + " b) " + comparator + " c FROM t"); |
90 | | - } |
91 | | - } |
92 | | - |
93 | | - @ParameterizedTest |
94 | | - @ValueSource(strings = {"<->", "<#>", "<=>"}) |
95 | | - void testVectorDistanceOperatorsShareBitwisePrecedence(String distance) |
96 | | - throws JSQLParserException { |
97 | | - Class<?> distanceType = |
98 | | - "<=>".equals(distance) ? CosineSimilarity.class : GeometryDistance.class; |
99 | | - |
100 | | - TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT a " + distance + " b & c FROM t"); |
101 | | - TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT a & b " + distance + " c FROM t"); |
102 | | - |
103 | | - BinaryExpression bitwiseRoot = |
104 | | - (BinaryExpression) CCJSqlParserUtil.parseExpression("a " + distance + " b & c"); |
105 | | - Assertions.assertInstanceOf(BitwiseAnd.class, bitwiseRoot); |
106 | | - Assertions.assertInstanceOf(distanceType, bitwiseRoot.getLeftExpression()); |
107 | | - |
108 | | - BinaryExpression distanceRoot = |
109 | | - (BinaryExpression) CCJSqlParserUtil.parseExpression("a & b " + distance + " c"); |
110 | | - Assertions.assertInstanceOf(distanceType, distanceRoot); |
111 | | - Assertions.assertInstanceOf(BitwiseAnd.class, distanceRoot.getLeftExpression()); |
112 | | - } |
113 | | - |
114 | | - @Test |
115 | | - void testGeometryDistanceOrderByControl() throws JSQLParserException { |
116 | | - TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT * FROM t ORDER BY a <-> b"); |
117 | | - TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT * FROM t ORDER BY a <#> b"); |
118 | | - } |
119 | | - |
120 | | - @Test |
121 | | - void testVectorDistancePrecedenceAboveComparisonBelowArithmetic() throws JSQLParserException { |
122 | | - BinaryExpression geometryComparison = Assertions.assertInstanceOf(MinorThan.class, |
123 | | - CCJSqlParserUtil.parseExpression("a <-> b + c < 5")); |
124 | | - GeometryDistance geometryDistance = Assertions.assertInstanceOf(GeometryDistance.class, |
125 | | - geometryComparison.getLeftExpression()); |
126 | | - Assertions.assertInstanceOf(Addition.class, geometryDistance.getRightExpression()); |
127 | | - |
128 | | - BinaryExpression cosineComparison = Assertions.assertInstanceOf(MinorThan.class, |
129 | | - CCJSqlParserUtil.parseExpression("a <=> b + c < 5")); |
130 | | - CosineSimilarity cosineSimilarity = Assertions.assertInstanceOf(CosineSimilarity.class, |
131 | | - cosineComparison.getLeftExpression()); |
132 | | - Assertions.assertInstanceOf(Addition.class, cosineSimilarity.getRightExpression()); |
133 | | - } |
134 | | - |
135 | | - @Test |
136 | | - void testComparisonChainsRemainInvalid() { |
137 | | - Assertions.assertThrows(JSQLParserException.class, |
138 | | - () -> CCJSqlParserUtil.parse("SELECT * FROM t WHERE a < b < c")); |
139 | | - Assertions.assertThrows(JSQLParserException.class, |
140 | | - () -> CCJSqlParserUtil.parse("SELECT * FROM t WHERE a <-> b < c < d")); |
141 | | - } |
142 | 46 | } |
0 commit comments