SQL: Fix bug in transforming Expression properties (elastic/x-pack-elasticsearch#4373)

Fix bug in checking whether the expression properties has been  
modified or not.

Change test to move from SIN to SQRT (as the former seem to return
different values (extra digit) across JDK versions - 8 vs 10)

Fix elastic/x-pack-elasticsearch#4335

Original commit: elastic/x-pack-elasticsearch@8f672c455d
This commit is contained in:
Costin Leau 2018-04-16 19:46:33 +03:00 committed by GitHub
parent 13d08f9c42
commit e113d5dda1
5 changed files with 35 additions and 11 deletions

View File

@ -5,13 +5,6 @@
*/
package org.elasticsearch.xpack.sql.plan;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import org.elasticsearch.xpack.sql.expression.Attribute;
import org.elasticsearch.xpack.sql.expression.AttributeSet;
import org.elasticsearch.xpack.sql.expression.Expression;
@ -19,6 +12,13 @@ import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.Node;
import org.elasticsearch.xpack.sql.type.DataType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* There are two main types of plans, {@code LogicalPlan} and {@code PhysicalPlan}
*/
@ -83,7 +83,7 @@ public abstract class QueryPlan<PlanType extends QueryPlan<PlanType>> extends No
boolean hasChanged = false;
for (Object e : c) {
Object next = doTransformExpression(e, traversal);
if (!c.equals(next)) {
if (!e.equals(next)) {
hasChanged = true;
}
else {

View File

@ -129,6 +129,13 @@ public class SysTablesTests extends ESTestCase {
}, index, alias);
}
public void testSysTablesWithCatalogOnlyAliases() throws Exception {
executeCommand("SYS TABLES CATALOG LIKE '%' LIKE 'test' TYPE 'ALIAS'", r -> {
assertEquals(1, r.size());
assertEquals("alias", r.column(2));
}, alias);
}
public void testSysTablesWithInvalidType() throws Exception {
ParsingException pe = expectThrows(ParsingException.class, () -> sql("SYS TABLES LIKE 'test' TYPE 'QUE HORA ES'"));
assertEquals("line 1:2: Invalid table type [QUE HORA ES]", pe.getMessage());

View File

@ -71,6 +71,23 @@ public class DatabaseMetaDataTestCase extends JdbcIntegrationTestCase {
}
}
public void testGetTableTypes() throws Exception {
index("test1", body -> body.field("name", "bob"));
index("test2", body -> body.field("name", "bob"));
try (Connection h2 = LocalH2.anonymousDb(); Connection es = esJdbc()) {
h2.createStatement().executeUpdate("RUNSCRIPT FROM 'classpath:/setup_mock_metadata_get_table_types.sql'");
CheckedSupplier<ResultSet, SQLException> all = () -> h2.createStatement()
.executeQuery("SELECT '" + clusterName() + "' AS TABLE_CAT, * FROM mock");
assertResultSets(all.get(), es.getMetaData().getTables("%", "%", "%", new String[] { "BASE TABLE" }));
assertResultSets(
h2.createStatement()
.executeQuery("SELECT '" + clusterName() + "' AS TABLE_CAT, * FROM mock WHERE TABLE_NAME = 'test1'"),
es.getMetaData().getTables("%", "%", "test1", new String[] { "BASE TABLE" }));
}
}
public void testColumns() throws Exception {
index("test1", body -> body.field("name", "bob"));
index("test2", body -> {

View File

@ -84,7 +84,7 @@ public abstract class RestSqlTestCase extends ESRestTestCase implements ErrorsTe
new StringEntity(bulk.toString(), ContentType.APPLICATION_JSON));
String request = "{\"query\":\""
+ " SELECT text, number, SIN(number) AS s, SCORE()"
+ " SELECT text, number, SQRT(number) AS s, SCORE()"
+ " FROM test"
+ " ORDER BY number, SCORE()\", "
+ "\"mode\":\"" + mode + "\", "
@ -109,8 +109,8 @@ public abstract class RestSqlTestCase extends ESRestTestCase implements ErrorsTe
columnInfo(mode, "SCORE()", "float", JDBCType.REAL, 15)));
}
expected.put("rows", Arrays.asList(
Arrays.asList("text" + i, i, Math.sin(i), 1.0),
Arrays.asList("text" + (i + 1), i + 1, Math.sin(i + 1), 1.0)));
Arrays.asList("text" + i, i, Math.sqrt(i), 1.0),
Arrays.asList("text" + (i + 1), i + 1, Math.sqrt(i + 1), 1.0)));
cursor = (String) response.remove("cursor");
assertResponse(expected, response);
assertNotNull(cursor);