Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions x-pack/plugin/sql/qa/src/main/resources/functions.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,33 @@ cct:s
AlejandroMcAlpine
;

selectConcatWithNullValues
SELECT first_name, CONCAT(first_name,null),last_name, CONCAT(null,null), LENGTH(CONCAT(null,null)) FROM test_emp ORDER BY first_name DESC LIMIT 20;

first_name:s |CONCAT(first_name,null):s| last_name:s |CONCAT(null,null):s|LENGTH(CONCAT(null,null)):i
---------------+-------------------------+----------------+-------------------+-------------------------
null | |Demeyer | |0
null | |Joslin | |0
null | |Reistad | |0
null | |Merlo | |0
null | |Swan | |0
null | |Chappelet | |0
null | |Portugali | |0
null | |Makrucki | |0
null | |Lortz | |0
null | |Brender | |0
Zvonko |Zvonko |Nyanchama | |0
Zhongwei |Zhongwei |Rosen | |0
Yongqiao |Yongqiao |Berztiss | |0
Yishay |Yishay |Tzvieli | |0
Yinghua |Yinghua |Dredge | |0
Xinglin |Xinglin |Eugenio | |0
Weiyi |Weiyi |Meriste | |0
Vishv |Vishv |Zockler | |0
Valter |Valter |Sullins | |0
Valdiodio |Valdiodio |Niizuma | |0
;

selectAsciiOfConcatWithGroupByOrderByCount
SELECT ASCII(CONCAT("first_name","last_name")) ascii, COUNT(*) count FROM "test_emp" GROUP BY ASCII(CONCAT("first_name","last_name")) ORDER BY ASCII(CONCAT("first_name","last_name")) DESC LIMIT 10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected Pipe makePipe() {

@Override
public boolean nullable() {
return left().nullable() && right().nullable();
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DayName;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DayOfMonth;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DayOfYear;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.MonthOfYear;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.IsoWeekOfYear;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.MonthOfYear;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.Year;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.ACos;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.ASin;
Expand All @@ -34,6 +34,7 @@
import org.elasticsearch.xpack.sql.expression.function.scalar.math.E;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Floor;
import org.elasticsearch.xpack.sql.expression.function.scalar.string.Ascii;
import org.elasticsearch.xpack.sql.expression.function.scalar.string.Concat;
import org.elasticsearch.xpack.sql.expression.function.scalar.string.Repeat;
import org.elasticsearch.xpack.sql.expression.predicate.BinaryOperator;
import org.elasticsearch.xpack.sql.expression.predicate.Range;
Expand Down Expand Up @@ -87,6 +88,7 @@
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.EsField;
import org.elasticsearch.xpack.sql.util.CollectionUtils;
import org.elasticsearch.xpack.sql.util.StringUtils;

import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -520,6 +522,13 @@ public void testSimplifyLeastRandomNullsWithValue() {
assertEquals(ONE, e.children().get(0));
assertEquals(TWO, e.children().get(1));
}

public void testConcatFoldingIsNotNull() {
FoldNull foldNull = new FoldNull();
assertEquals(1, foldNull.rule(new Concat(EMPTY, Literal.NULL, ONE)).fold());
assertEquals(1, foldNull.rule(new Concat(EMPTY, ONE, Literal.NULL)).fold());
assertEquals(StringUtils.EMPTY, foldNull.rule(new Concat(EMPTY, Literal.NULL, Literal.NULL)).fold());
}

//
// Logical simplifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,14 @@ public void testGroupKeyTypes_Date() {
assertThat(ee.output().get(0).toString(), startsWith("COUNT(1){a->"));
assertThat(ee.output().get(1).toString(), startsWith("a{s->"));
}

public void testConcatIsNotFoldedForNull() {
PhysicalPlan p = plan("SELECT keyword FROM test WHERE CONCAT(keyword, null) IS NULL");
assertEquals(LocalExec.class, p.getClass());
LocalExec le = (LocalExec) p;
assertEquals(EmptyExecutable.class, le.executable().getClass());
EmptyExecutable ee = (EmptyExecutable) le.executable();
assertEquals(1, ee.output().size());
assertThat(ee.output().get(0).toString(), startsWith("keyword{f}#"));
}
}