ignite-sql-tests - UUID fix
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4bf6436c Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4bf6436c Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4bf6436c Branch: refs/heads/ignite-432 Commit: 4bf6436cd19fe73b1f63b15ddd589450f24cc36e Parents: c80dd85 Author: S.Vladykin <svlady...@gridgain.com> Authored: Sat Mar 14 20:53:26 2015 +0300 Committer: S.Vladykin <svlady...@gridgain.com> Committed: Sat Mar 14 20:53:26 2015 +0300 ---------------------------------------------------------------------- .../processors/query/h2/sql/GridSqlElement.java | 17 ++ .../query/h2/sql/GridSqlQueryParser.java | 6 + .../query/h2/sql/GridSqlQuerySplitter.java | 4 + .../processors/query/h2/sql/GridSqlType.java | 94 ++++++++++ .../h2/twostep/GridReduceQueryExecutor.java | 182 +++++-------------- 5 files changed, 170 insertions(+), 133 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4bf6436c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlElement.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlElement.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlElement.java index 62370ba..e36d6ff 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlElement.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlElement.java @@ -26,6 +26,23 @@ public abstract class GridSqlElement implements Cloneable, Iterable<GridSqlEleme /** */ protected List<GridSqlElement> children = new ArrayList<>(); + /** */ + private GridSqlType expressionResultType; + + /** + * @return Optional expression result type. + */ + public GridSqlType expressionResultType() { + return expressionResultType; + } + + /** + * @param type Optional expression result type (if this is expression). + */ + public void expressionResultType(GridSqlType type) { + expressionResultType = type; + } + /** {@inheritDoc} */ public abstract String getSQL(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4bf6436c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java index fbb75d4..acb72ac 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java @@ -307,6 +307,12 @@ public class GridSqlQueryParser { if (res == null) { res = parseExpression0(expression); + Column c = new Column(null, expression.getType(), expression.getPrecision(), expression.getScale(), + expression.getDisplaySize()); + + res.expressionResultType(new GridSqlType(c.getType(), c.getScale(), c.getPrecision(), c.getDisplaySize(), + c.getCreateSQL())); + h2ObjToGridObj.put(expression, res); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4bf6436c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java index 9877e61..ea146ca 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java @@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.query.h2.sql; import org.apache.ignite.*; import org.apache.ignite.internal.processors.cache.query.*; +import org.h2.value.*; import java.sql.*; import java.util.*; @@ -311,6 +312,9 @@ public class GridSqlQuerySplitter { if (idx < rdcSelect.length) { // SELECT __C0 AS orginal_alias GridSqlElement rdcEl = column(mapColAlias); + if (el.expressionResultType().type() == Value.UUID) + rdcEl = function(CAST).setCastType("UUID").addChild(rdcEl); + if (colNames.add(rdcColAlias)) rdcEl = alias(rdcColAlias, rdcEl); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4bf6436c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlType.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlType.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlType.java new file mode 100644 index 0000000..117313d --- /dev/null +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlType.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.query.h2.sql; + +/** + * SQL Data type based on H2. + */ +public class GridSqlType { + /** H2 type. */ + private int type; + + /** */ + private int scale; + + /** */ + private long precision; + + /** */ + private int displaySize; + + /** */ + private String sql; + + /** + * @param type H2 Type. + * @param scale Scale. + * @param precision Precision. + * @param displaySize Display size. + * @param sql SQL definition of the type. + */ + public GridSqlType(int type, int scale, long precision, int displaySize, String sql) { + this.type = type; + this.scale = scale; + this.precision = precision; + this.displaySize = displaySize; + this.sql = sql; + } + + /** + * @return Get H2 type. + */ + public int type() { + return type; + } + + /** + * Get the scale of this expression. + * + * @return Scale. + */ + public int scale() { + return scale; + } + + /** + * Get the precision of this expression. + * + * @return Precision. + */ + public long precision() { + return precision; + } + + /** + * Get the display size of this expression. + * + * @return the display size + */ + public int displaySize() { + return displaySize; + } + + /** + * @return SQL definition of the type. + */ + public String sql() { + return sql; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4bf6436c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java index 1d6bb99..365fb43 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java @@ -40,9 +40,10 @@ import org.h2.index.*; import org.h2.jdbc.*; import org.h2.result.*; import org.h2.table.*; +import org.h2.tools.*; +import org.h2.util.*; import org.h2.value.*; import org.jdk8.backport.*; -import org.jetbrains.annotations.*; import javax.cache.*; import java.lang.reflect.*; @@ -128,7 +129,7 @@ public class GridReduceQueryExecutor implements GridMessageListener { }, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT); h2.executeStatement("PUBLIC", "CREATE ALIAS " + GridSqlQuerySplitter.TABLE_FUNC_NAME + - " FOR \"" + GridReduceQueryExecutor.class.getName() + ".mergeTableFunction\""); + " NOBUFFER FOR \"" + GridReduceQueryExecutor.class.getName() + ".mergeTableFunction\""); } /** {@inheritDoc} */ @@ -357,9 +358,53 @@ public class GridReduceQueryExecutor implements GridMessageListener { String url = c.getMetaData().getURL(); // URL is either "jdbc:default:connection" or "jdbc:columnlist:connection" - Cursor cursor = url.charAt(5) == 'c' ? null : tbl.getScanIndex(ses).find(ses, null, null); + final Cursor cursor = url.charAt(5) == 'c' ? null : tbl.getScanIndex(ses).find(ses, null, null); - return CONSTRUCTOR.newInstance(c, null, new Result0(cursor, tbl.getColumns()), 0, false, false, false); + final Column[] cols = tbl.getColumns(); + + SimpleResultSet rs = new SimpleResultSet(cursor == null ? null : new SimpleRowSource() { + @Override public Object[] readRow() throws SQLException { + if (!cursor.next()) + return null; + + Row r = cursor.get(); + + Object[] row = new Object[cols.length]; + + for (int i = 0; i < row.length; i++) + row[i] = r.getValue(i).getObject(); + + return row; + } + + @Override public void close() { + // No-op. + } + + @Override public void reset() throws SQLException { + throw new SQLException("Unsupported."); + } + }) { + @Override public byte[] getBytes(int colIdx) throws SQLException { + assert cursor != null; + + return cursor.get().getValue(colIdx - 1).getBytes(); + } + + @Override public <T> T getObject(int columnIndex, Class<T> type) throws SQLException { + throw new UnsupportedOperationException(); + } + + @Override public <T> T getObject(String columnLabel, Class<T> type) throws SQLException { + throw new UnsupportedOperationException(); + } + }; + + for (Column col : cols) + rs.addColumn(col.getName(), DataType.convertTypeToSQLType(col.getType()), + MathUtils.convertLongToInt(col.getPrecision()), col.getScale()); + + return rs; } /** @@ -493,133 +538,4 @@ public class GridReduceQueryExecutor implements GridMessageListener { return res; } } - - /** - * Query result for H2. - */ - private static class Result0 implements ResultInterface { - /** */ - private Cursor cursor; - - /** */ - private Column[] cols; - - /** */ - private int rowId; - - /** - * @param cursor Cursor. - * @param cols Columns. - */ - Result0(@Nullable Cursor cursor, Column[] cols) { - this.cursor = cursor != null ? cursor : new SingleRowCursor(null); - this.cols = cols; - } - - /** {@inheritDoc} */ - @Override public void reset() { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public Value[] currentRow() { - return cursor.get().getValueList(); - } - - /** {@inheritDoc} */ - @Override public boolean next() { - if (cursor.next()) { - rowId++; - - return true; - } - - return false; - } - - /** {@inheritDoc} */ - @Override public int getRowId() { - return rowId; - } - - /** {@inheritDoc} */ - @Override public int getVisibleColumnCount() { - return cols.length; - } - - /** {@inheritDoc} */ - @Override public int getRowCount() { - return Integer.MAX_VALUE; - } - - /** {@inheritDoc} */ - @Override public boolean needToClose() { - return false; - } - - /** {@inheritDoc} */ - @Override public void close() { - // No-op. - } - - /** {@inheritDoc} */ - @Override public String getAlias(int i) { - return cols[i].getName(); - } - - /** {@inheritDoc} */ - @Override public String getSchemaName(int i) { - return cols[i].getTable().getSchema().getName(); - } - - /** {@inheritDoc} */ - @Override public String getTableName(int i) { - return cols[i].getTable().getName(); - } - - /** {@inheritDoc} */ - @Override public String getColumnName(int i) { - return cols[i].getName(); - } - - /** {@inheritDoc} */ - @Override public int getColumnType(int i) { - return cols[i].getType(); - } - - /** {@inheritDoc} */ - @Override public long getColumnPrecision(int i) { - return cols[i].getPrecision(); - } - - /** {@inheritDoc} */ - @Override public int getColumnScale(int i) { - return cols[i].getScale(); - } - - /** {@inheritDoc} */ - @Override public int getDisplaySize(int i) { - return cols[i].getDisplaySize(); - } - - /** {@inheritDoc} */ - @Override public boolean isAutoIncrement(int i) { - return cols[i].isAutoIncrement(); - } - - /** {@inheritDoc} */ - @Override public int getNullable(int i) { - return Column.NULLABLE_UNKNOWN; - } - - /** {@inheritDoc} */ - @Override public void setFetchSize(int fetchSize) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public int getFetchSize() { - throw new UnsupportedOperationException(); - } - } }