|
@@ -76,7 +76,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
|
|
|
|
EsIndex test = new EsIndex("test", mapping);
|
|
EsIndex test = new EsIndex("test", mapping);
|
|
getIndexResult = IndexResolution.valid(test);
|
|
getIndexResult = IndexResolution.valid(test);
|
|
- analyzer = new Analyzer(SqlTestUtils.TEST_CFG, functionRegistry, getIndexResult, verifier);
|
|
|
|
|
|
+ analyzer = analyzer(functionRegistry, getIndexResult, verifier);
|
|
}
|
|
}
|
|
|
|
|
|
private LogicalPlan plan(String sql) {
|
|
private LogicalPlan plan(String sql) {
|
|
@@ -197,7 +197,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
|
|
|
|
EsIndex index = new EsIndex("test", mapping);
|
|
EsIndex index = new EsIndex("test", mapping);
|
|
getIndexResult = IndexResolution.valid(index);
|
|
getIndexResult = IndexResolution.valid(index);
|
|
- analyzer = new Analyzer(SqlTestUtils.TEST_CFG, functionRegistry, getIndexResult, verifier);
|
|
|
|
|
|
+ analyzer = analyzer(functionRegistry, getIndexResult, verifier);
|
|
|
|
|
|
VerificationException ex = expectThrows(VerificationException.class, () -> plan("SELECT test.bar FROM test"));
|
|
VerificationException ex = expectThrows(VerificationException.class, () -> plan("SELECT test.bar FROM test"));
|
|
assertEquals(
|
|
assertEquals(
|
|
@@ -232,7 +232,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
Map<String, EsField> mapping = TypesTests.loadMapping("mapping-basic.json");
|
|
Map<String, EsField> mapping = TypesTests.loadMapping("mapping-basic.json");
|
|
EsIndex index = new EsIndex("test", mapping);
|
|
EsIndex index = new EsIndex("test", mapping);
|
|
getIndexResult = IndexResolution.valid(index);
|
|
getIndexResult = IndexResolution.valid(index);
|
|
- analyzer = new Analyzer(SqlTestUtils.TEST_CFG, functionRegistry, getIndexResult, verifier);
|
|
|
|
|
|
+ analyzer = analyzer(functionRegistry, getIndexResult, verifier);
|
|
|
|
|
|
LogicalPlan plan = plan("SELECT sum(salary) AS s FROM test");
|
|
LogicalPlan plan = plan("SELECT sum(salary) AS s FROM test");
|
|
assertThat(plan, instanceOf(Aggregate.class));
|
|
assertThat(plan, instanceOf(Aggregate.class));
|
|
@@ -265,7 +265,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
Map<String, EsField> mapping = TypesTests.loadMapping("mapping-basic.json");
|
|
Map<String, EsField> mapping = TypesTests.loadMapping("mapping-basic.json");
|
|
EsIndex index = new EsIndex("test", mapping);
|
|
EsIndex index = new EsIndex("test", mapping);
|
|
getIndexResult = IndexResolution.valid(index);
|
|
getIndexResult = IndexResolution.valid(index);
|
|
- analyzer = new Analyzer(SqlTestUtils.TEST_CFG, functionRegistry, getIndexResult, verifier);
|
|
|
|
|
|
+ analyzer = analyzer(functionRegistry, getIndexResult, verifier);
|
|
|
|
|
|
VerificationException ex = expectThrows(
|
|
VerificationException ex = expectThrows(
|
|
VerificationException.class,
|
|
VerificationException.class,
|
|
@@ -323,7 +323,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
SqlConfiguration sqlConfig = SqlTestUtils.randomConfiguration(SqlVersion.fromId(preUnsignedLong.id));
|
|
SqlConfiguration sqlConfig = SqlTestUtils.randomConfiguration(SqlVersion.fromId(preUnsignedLong.id));
|
|
|
|
|
|
for (String sql : List.of(query, queryWithLiteral, queryWithCastLiteral, queryWithAlias, queryWithArithmetic, queryWithCast)) {
|
|
for (String sql : List.of(query, queryWithLiteral, queryWithCastLiteral, queryWithAlias, queryWithArithmetic, queryWithCast)) {
|
|
- analyzer = new Analyzer(
|
|
|
|
|
|
+ analyzer = analyzer(
|
|
sqlConfig,
|
|
sqlConfig,
|
|
functionRegistry,
|
|
functionRegistry,
|
|
loadCompatibleIndexResolution("mapping-numeric.json", preUnsignedLong),
|
|
loadCompatibleIndexResolution("mapping-numeric.json", preUnsignedLong),
|
|
@@ -333,7 +333,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
assertThat(ex.getMessage(), containsString("Found 1 problem\nline 1:8: Cannot use field [unsigned_long]"));
|
|
assertThat(ex.getMessage(), containsString("Found 1 problem\nline 1:8: Cannot use field [unsigned_long]"));
|
|
|
|
|
|
for (Version v : List.of(INTRODUCING_UNSIGNED_LONG, postUnsignedLong)) {
|
|
for (Version v : List.of(INTRODUCING_UNSIGNED_LONG, postUnsignedLong)) {
|
|
- analyzer = new Analyzer(
|
|
|
|
|
|
+ analyzer = analyzer(
|
|
SqlTestUtils.randomConfiguration(SqlVersion.fromId(v.id)),
|
|
SqlTestUtils.randomConfiguration(SqlVersion.fromId(v.id)),
|
|
functionRegistry,
|
|
functionRegistry,
|
|
loadCompatibleIndexResolution("mapping-numeric.json", v),
|
|
loadCompatibleIndexResolution("mapping-numeric.json", v),
|
|
@@ -362,7 +362,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
SqlConfiguration sqlConfig = SqlTestUtils.randomConfiguration(SqlVersion.fromId(preVersion.id));
|
|
SqlConfiguration sqlConfig = SqlTestUtils.randomConfiguration(SqlVersion.fromId(preVersion.id));
|
|
|
|
|
|
for (String sql : List.of(query, queryWithCastLiteral, queryWithAlias, queryWithCast)) {
|
|
for (String sql : List.of(query, queryWithCastLiteral, queryWithAlias, queryWithCast)) {
|
|
- analyzer = new Analyzer(
|
|
|
|
|
|
+ analyzer = analyzer(
|
|
sqlConfig,
|
|
sqlConfig,
|
|
functionRegistry,
|
|
functionRegistry,
|
|
loadCompatibleIndexResolution("mapping-version.json", preVersion),
|
|
loadCompatibleIndexResolution("mapping-version.json", preVersion),
|
|
@@ -372,7 +372,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
assertThat(ex.getMessage(), containsString("Cannot use field [version_number]"));
|
|
assertThat(ex.getMessage(), containsString("Cannot use field [version_number]"));
|
|
|
|
|
|
for (Version v : List.of(INTRODUCING_VERSION_FIELD_TYPE, postVersion)) {
|
|
for (Version v : List.of(INTRODUCING_VERSION_FIELD_TYPE, postVersion)) {
|
|
- analyzer = new Analyzer(
|
|
|
|
|
|
+ analyzer = analyzer(
|
|
SqlTestUtils.randomConfiguration(SqlVersion.fromId(v.id)),
|
|
SqlTestUtils.randomConfiguration(SqlVersion.fromId(v.id)),
|
|
functionRegistry,
|
|
functionRegistry,
|
|
loadCompatibleIndexResolution("mapping-version.json", v),
|
|
loadCompatibleIndexResolution("mapping-version.json", v),
|
|
@@ -393,7 +393,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
public void testNonProjectedUnsignedLongVersionCompatibility() {
|
|
public void testNonProjectedUnsignedLongVersionCompatibility() {
|
|
Version preUnsignedLong = Version.fromId(INTRODUCING_UNSIGNED_LONG.id - SqlVersion.MINOR_MULTIPLIER);
|
|
Version preUnsignedLong = Version.fromId(INTRODUCING_UNSIGNED_LONG.id - SqlVersion.MINOR_MULTIPLIER);
|
|
SqlConfiguration sqlConfig = SqlTestUtils.randomConfiguration(SqlVersion.fromId(preUnsignedLong.id));
|
|
SqlConfiguration sqlConfig = SqlTestUtils.randomConfiguration(SqlVersion.fromId(preUnsignedLong.id));
|
|
- analyzer = new Analyzer(
|
|
|
|
|
|
+ analyzer = analyzer(
|
|
sqlConfig,
|
|
sqlConfig,
|
|
functionRegistry,
|
|
functionRegistry,
|
|
loadCompatibleIndexResolution("mapping-numeric.json", preUnsignedLong),
|
|
loadCompatibleIndexResolution("mapping-numeric.json", preUnsignedLong),
|
|
@@ -427,7 +427,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
String sql = "SELECT container.ul as unsigned_long FROM test";
|
|
String sql = "SELECT container.ul as unsigned_long FROM test";
|
|
|
|
|
|
Version preUnsignedLong = Version.fromId(INTRODUCING_UNSIGNED_LONG.id - SqlVersion.MINOR_MULTIPLIER);
|
|
Version preUnsignedLong = Version.fromId(INTRODUCING_UNSIGNED_LONG.id - SqlVersion.MINOR_MULTIPLIER);
|
|
- analyzer = new Analyzer(
|
|
|
|
|
|
+ analyzer = analyzer(
|
|
SqlTestUtils.randomConfiguration(SqlVersion.fromId(preUnsignedLong.id)),
|
|
SqlTestUtils.randomConfiguration(SqlVersion.fromId(preUnsignedLong.id)),
|
|
functionRegistry,
|
|
functionRegistry,
|
|
compatibleIndexResolution(props, preUnsignedLong),
|
|
compatibleIndexResolution(props, preUnsignedLong),
|
|
@@ -438,7 +438,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
|
|
|
|
Version postUnsignedLong = Version.fromId(INTRODUCING_UNSIGNED_LONG.id + SqlVersion.MINOR_MULTIPLIER);
|
|
Version postUnsignedLong = Version.fromId(INTRODUCING_UNSIGNED_LONG.id + SqlVersion.MINOR_MULTIPLIER);
|
|
for (Version v : List.of(INTRODUCING_UNSIGNED_LONG, postUnsignedLong)) {
|
|
for (Version v : List.of(INTRODUCING_UNSIGNED_LONG, postUnsignedLong)) {
|
|
- analyzer = new Analyzer(
|
|
|
|
|
|
+ analyzer = analyzer(
|
|
SqlTestUtils.randomConfiguration(SqlVersion.fromId(v.id)),
|
|
SqlTestUtils.randomConfiguration(SqlVersion.fromId(v.id)),
|
|
functionRegistry,
|
|
functionRegistry,
|
|
compatibleIndexResolution(props, v),
|
|
compatibleIndexResolution(props, v),
|
|
@@ -463,7 +463,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
for (SqlVersion version : List.of(preUnsignedLong, SqlVersion.fromId(INTRODUCING_UNSIGNED_LONG.id), postUnsignedLong)) {
|
|
for (SqlVersion version : List.of(preUnsignedLong, SqlVersion.fromId(INTRODUCING_UNSIGNED_LONG.id), postUnsignedLong)) {
|
|
SqlConfiguration config = SqlTestUtils.randomConfiguration(version);
|
|
SqlConfiguration config = SqlTestUtils.randomConfiguration(version);
|
|
// the mapping is mutated when making it "compatible", so it needs to be reloaded inside the loop.
|
|
// the mapping is mutated when making it "compatible", so it needs to be reloaded inside the loop.
|
|
- analyzer = new Analyzer(
|
|
|
|
|
|
+ analyzer = analyzer(
|
|
config,
|
|
config,
|
|
functionRegistry,
|
|
functionRegistry,
|
|
loadCompatibleIndexResolution("mapping-numeric.json", Version.fromId(version.id)),
|
|
loadCompatibleIndexResolution("mapping-numeric.json", Version.fromId(version.id)),
|
|
@@ -481,7 +481,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
}
|
|
}
|
|
|
|
|
|
public void testFunctionOverNonExistingFieldAsArgumentAndSameAlias() throws Exception {
|
|
public void testFunctionOverNonExistingFieldAsArgumentAndSameAlias() throws Exception {
|
|
- analyzer = new Analyzer(SqlTestUtils.TEST_CFG, functionRegistry, loadIndexResolution("mapping-basic.json"), verifier);
|
|
|
|
|
|
+ analyzer = analyzer(SqlTestUtils.TEST_CFG, functionRegistry, loadIndexResolution("mapping-basic.json"), verifier);
|
|
|
|
|
|
VerificationException ex = expectThrows(
|
|
VerificationException ex = expectThrows(
|
|
VerificationException.class,
|
|
VerificationException.class,
|
|
@@ -491,7 +491,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
}
|
|
}
|
|
|
|
|
|
public void testFunctionWithExpressionOverNonExistingFieldAsArgumentAndSameAlias() throws Exception {
|
|
public void testFunctionWithExpressionOverNonExistingFieldAsArgumentAndSameAlias() throws Exception {
|
|
- analyzer = new Analyzer(SqlTestUtils.TEST_CFG, functionRegistry, loadIndexResolution("mapping-basic.json"), verifier);
|
|
|
|
|
|
+ analyzer = analyzer(SqlTestUtils.TEST_CFG, functionRegistry, loadIndexResolution("mapping-basic.json"), verifier);
|
|
|
|
|
|
VerificationException ex = expectThrows(
|
|
VerificationException ex = expectThrows(
|
|
VerificationException.class,
|
|
VerificationException.class,
|
|
@@ -503,7 +503,7 @@ public class FieldAttributeTests extends ESTestCase {
|
|
public void testExpandStarOnIndexWithoutColumns() {
|
|
public void testExpandStarOnIndexWithoutColumns() {
|
|
EsIndex test = new EsIndex("test", Collections.emptyMap());
|
|
EsIndex test = new EsIndex("test", Collections.emptyMap());
|
|
getIndexResult = IndexResolution.valid(test);
|
|
getIndexResult = IndexResolution.valid(test);
|
|
- analyzer = new Analyzer(SqlTestUtils.TEST_CFG, functionRegistry, getIndexResult, verifier);
|
|
|
|
|
|
+ analyzer = analyzer(SqlTestUtils.TEST_CFG, functionRegistry, getIndexResult, verifier);
|
|
|
|
|
|
LogicalPlan plan = plan("SELECT * FROM test");
|
|
LogicalPlan plan = plan("SELECT * FROM test");
|
|
|
|
|
|
@@ -529,4 +529,17 @@ public class FieldAttributeTests extends ESTestCase {
|
|
EsIndex index = new EsIndex("test", mapping);
|
|
EsIndex index = new EsIndex("test", mapping);
|
|
return IndexCompatibility.compatible(IndexResolution.valid(index), version);
|
|
return IndexCompatibility.compatible(IndexResolution.valid(index), version);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private static Analyzer analyzer(
|
|
|
|
+ SqlConfiguration configuration,
|
|
|
|
+ FunctionRegistry functionRegistry,
|
|
|
|
+ IndexResolution resolution,
|
|
|
|
+ Verifier verifier
|
|
|
|
+ ) {
|
|
|
|
+ return new Analyzer(new AnalyzerContext(configuration, functionRegistry, resolution), verifier);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static Analyzer analyzer(FunctionRegistry functionRegistry, IndexResolution resolution, Verifier verifier) {
|
|
|
|
+ return analyzer(SqlTestUtils.TEST_CFG, functionRegistry, resolution, verifier);
|
|
|
|
+ }
|
|
}
|
|
}
|