ignite-gg9499 - cast
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/88571b9a Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/88571b9a Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/88571b9a Branch: refs/heads/ignite-gg9499 Commit: 88571b9a6ebd6f262680d972ddb6a1a42a7463f8 Parents: 2168b09 Author: S.Vladykin <svlady...@gridgain.com> Authored: Tue Dec 23 23:35:05 2014 +0300 Committer: S.Vladykin <svlady...@gridgain.com> Committed: Tue Dec 23 23:35:05 2014 +0300 ---------------------------------------------------------------------- .../query/h2/sql/GridQueryParser.java | 10 +++++++--- .../query/h2/sql/GridSqlFunction.java | 21 ++++++++++++++------ .../processors/query/h2/sql/GridQueryTest.java | 6 ++++++ 3 files changed, 28 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/88571b9a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridQueryParser.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridQueryParser.java b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridQueryParser.java index d31bee3..780c662 100644 --- a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridQueryParser.java +++ b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridQueryParser.java @@ -330,13 +330,17 @@ public class GridQueryParser { } if (expression instanceof Function) { - Function function = (Function)expression; + Function f = (Function)expression; - GridSqlFunction res = new GridSqlFunction(function.getName()); + GridSqlFunction res = new GridSqlFunction(f.getName()); - for (Expression arg : function.getArgs()) + for (Expression arg : f.getArgs()) res.addChild(toGridExpression(arg)); + if (f.getFunctionType() == Function.CAST) + res.setCastType(new Column(null, f.getType(), f.getPrecision(), f.getScale(), f.getDisplaySize()) + .getCreateSQL()); + return res; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/88571b9a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridSqlFunction.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridSqlFunction.java b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridSqlFunction.java index 5e9e112..6256380 100644 --- a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridSqlFunction.java +++ b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridSqlFunction.java @@ -9,6 +9,7 @@ package org.gridgain.grid.kernal.processors.query.h2.sql; +import org.gridgain.grid.util.typedef.*; import org.h2.util.*; import org.h2.value.*; @@ -35,6 +36,9 @@ public class GridSqlFunction extends GridSqlElement { /** */ protected final GridFunctionType type; + /** */ + private String castType; + /** * @param type Function type. */ @@ -43,7 +47,7 @@ public class GridSqlFunction extends GridSqlElement { this.type = type; - if (type == GridFunctionType.CAST || type == GridFunctionType.CONVERT) + if (type == GridFunctionType.CONVERT) throw new UnsupportedOperationException(); } @@ -52,9 +56,13 @@ public class GridSqlFunction extends GridSqlElement { */ public GridSqlFunction(String name) { this(TYPE_MAP.get(name)); + } - if (type == GridFunctionType.CAST || type == GridFunctionType.CONVERT) - throw new UnsupportedOperationException(); + /** + * @param castType Type for {@link GridFunctionType#CAST} function. + */ + public void setCastType(String castType) { + this.castType = castType; } /** {@inheritDoc} */ @@ -78,9 +86,10 @@ public class GridSqlFunction extends GridSqlElement { buff.append('('); if (type == GridFunctionType.CAST) { - throw new UnsupportedOperationException("CAST"); -// buff.append(child().getSQL()).append(" AS "). -// append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL()); + assert !F.isEmpty(castType) : castType; + assert children().size() == 1; + + buff.append(child().getSQL()).append(" AS ").append(castType); } else if (type == GridFunctionType.CONVERT) { throw new UnsupportedOperationException("CONVERT"); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/88571b9a/modules/indexing/src/test/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridQueryTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridQueryTest.java b/modules/indexing/src/test/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridQueryTest.java index 4feaba6..099bfc1 100644 --- a/modules/indexing/src/test/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridQueryTest.java +++ b/modules/indexing/src/test/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridQueryTest.java @@ -86,6 +86,10 @@ public class GridQueryTest extends GridCacheAbstractQuerySelfTest { checkQuery("select case p.name when 'a' then 1 when 'a' then 2 else -1 end as a from Person p"); checkQuery("select abs(p.old) from Person p"); + checkQuery("select cast(p.old as numeric(10, 2)) from Person p"); + checkQuery("select cast(p.old as numeric(10, 2)) z from Person p"); + checkQuery("select cast(p.old as numeric(10, 2)) as z from Person p"); + checkQuery("select * from Person p where p.name in ('a', 'b', '_' + RAND())"); // test ConditionIn checkQuery("select * from Person p where p.name in ('a', 'b', 'c')"); // test ConditionInConstantSet checkQuery("select * from Person p where p.name in (select a.street from Address a)"); // test ConditionInConstantSet @@ -120,6 +124,8 @@ public class GridQueryTest extends GridCacheAbstractQuerySelfTest { checkQuery("select p.name n from Person p, (select a.street from Address a where a.street is not null) "); checkQuery("select street from Person p, (select a.street from Address a where a.street is not null) "); checkQuery("select addr.street from Person p, (select a.street from Address a where a.street is not null) addr"); + + checkQuery("select p.name n from PUBLIC.Person p order by p.old + 10"); } /**