ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [11/24] incubator-ignite git commit: ignite-757 - direct marshalling for H2 types
Date Wed, 29 Apr 2015 13:35:15 GMT
ignite-757 - direct marshalling for H2 types


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/351001bd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/351001bd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/351001bd

Branch: refs/heads/ignite-sprint-4
Commit: 351001bdc6941f03560e2f269b1a47ab84c8f7a2
Parents: 59ec2f9
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Mon Apr 27 03:22:35 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Mon Apr 27 03:22:35 2015 +0300

----------------------------------------------------------------------
 .../ignite/codegen/MessageCodeGenerator.java    |  25 ++-
 .../ignite/internal/GridDirectCollection.java   |   3 +
 .../managers/communication/GridIoManager.java   |  23 ++-
 .../communication/GridIoMessageFactory.java     |   8 +
 .../cache/query/GridCacheSqlQuery.java          | 135 ++++++++++++--
 .../cache/query/GridCacheTwoStepQuery.java      |   8 +-
 .../processors/query/GridQueryIndexing.java     |   8 +
 .../processors/query/GridQueryProcessor.java    |   9 +
 .../messages/GridQueryNextPageResponse.java     |  68 ++++---
 .../h2/twostep/messages/GridQueryRequest.java   |  21 +--
 .../processors/query/h2/IgniteH2Indexing.java   | 152 +---------------
 .../query/h2/opt/GridH2ValueCacheObject.java    | 160 +++++++++++++++++
 .../query/h2/twostep/GridMapQueryExecutor.java  |  21 ++-
 .../query/h2/twostep/GridMergeIndex.java        |   2 +-
 .../h2/twostep/GridMergeIndexUnsorted.java      |   4 +-
 .../h2/twostep/GridReduceQueryExecutor.java     |  11 +-
 .../query/h2/twostep/GridResultPage.java        |  69 ++++++-
 .../query/h2/twostep/msg/GridH2Array.java       | 106 +++++++++++
 .../query/h2/twostep/msg/GridH2Boolean.java     |  94 ++++++++++
 .../query/h2/twostep/msg/GridH2Byte.java        |  95 ++++++++++
 .../query/h2/twostep/msg/GridH2Bytes.java       |  95 ++++++++++
 .../query/h2/twostep/msg/GridH2Date.java        |  97 ++++++++++
 .../query/h2/twostep/msg/GridH2Decimal.java     |  95 ++++++++++
 .../query/h2/twostep/msg/GridH2Double.java      |  95 ++++++++++
 .../query/h2/twostep/msg/GridH2Float.java       |  95 ++++++++++
 .../query/h2/twostep/msg/GridH2Geometry.java    | 116 ++++++++++++
 .../query/h2/twostep/msg/GridH2Integer.java     |  95 ++++++++++
 .../query/h2/twostep/msg/GridH2JavaObject.java  |  95 ++++++++++
 .../query/h2/twostep/msg/GridH2Long.java        |  95 ++++++++++
 .../query/h2/twostep/msg/GridH2Null.java        |  66 +++++++
 .../query/h2/twostep/msg/GridH2Short.java       |  95 ++++++++++
 .../query/h2/twostep/msg/GridH2String.java      |  97 ++++++++++
 .../query/h2/twostep/msg/GridH2Time.java        |  98 ++++++++++
 .../query/h2/twostep/msg/GridH2Timestamp.java   | 115 ++++++++++++
 .../query/h2/twostep/msg/GridH2Uuid.java        | 115 ++++++++++++
 .../h2/twostep/msg/GridH2ValueMessage.java      |  28 +++
 .../twostep/msg/GridH2ValueMessageFactory.java  | 179 +++++++++++++++++++
 37 files changed, 2472 insertions(+), 221 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java b/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
index f75bcf4..eef4dd6 100644
--- a/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
+++ b/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.codegen;
 
 import org.apache.ignite.internal.*;
-import org.apache.ignite.internal.processors.datastreamer.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.plugin.extensions.communication.*;
@@ -46,6 +45,9 @@ public class MessageCodeGenerator {
     private static final String DFLT_SRC_DIR = U.getIgniteHome() + "/modules/core/src/main/java";
 
     /** */
+    private static final String INDEXING_SRC_DIR = U.getIgniteHome() + "/modules/indexing/src/main/java";
+
+    /** */
     private static final Class<?> BASE_CLS = Message.class;
 
     /** */
@@ -140,7 +142,7 @@ public class MessageCodeGenerator {
 
         MessageCodeGenerator gen = new MessageCodeGenerator(srcDir);
 
-        gen.generateAndWrite(DataStreamerEntry.class);
+//        gen.generateAndWrite(DataStreamerEntry.class);
 
 //        gen.generateAndWrite(GridDistributedLockRequest.class);
 //        gen.generateAndWrite(GridDistributedLockResponse.class);
@@ -172,6 +174,25 @@ public class MessageCodeGenerator {
 //        gen.generateAndWrite(GridQueryNextPageResponse.class);
 //        gen.generateAndWrite(GridQueryRequest.class);
 //        gen.generateAndWrite(GridCacheSqlQuery.class);
+
+//        gen.generateAndWrite(GridH2Null.class);
+//        gen.generateAndWrite(GridH2Boolean.class);
+//        gen.generateAndWrite(GridH2Byte.class);
+//        gen.generateAndWrite(GridH2Short.class);
+//        gen.generateAndWrite(GridH2Integer.class);
+//        gen.generateAndWrite(GridH2Long.class);
+//        gen.generateAndWrite(GridH2Decimal.class);
+//        gen.generateAndWrite(GridH2Double.class);
+//        gen.generateAndWrite(GridH2Float.class);
+//        gen.generateAndWrite(GridH2Time.class);
+//        gen.generateAndWrite(GridH2Date.class);
+//        gen.generateAndWrite(GridH2Timestamp.class);
+//        gen.generateAndWrite(GridH2Bytes.class);
+//        gen.generateAndWrite(GridH2String.class);
+//        gen.generateAndWrite(GridH2Array.class);
+//        gen.generateAndWrite(GridH2JavaObject.class);
+//        gen.generateAndWrite(GridH2Uuid.class);
+//        gen.generateAndWrite(GridH2Geometry.class);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/core/src/main/java/org/apache/ignite/internal/GridDirectCollection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridDirectCollection.java b/modules/core/src/main/java/org/apache/ignite/internal/GridDirectCollection.java
index 61144d6..58c1c29 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridDirectCollection.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridDirectCollection.java
@@ -17,10 +17,13 @@
 
 package org.apache.ignite.internal;
 
+import org.apache.ignite.plugin.extensions.communication.*;
+
 import java.lang.annotation.*;
 
 /**
  * Annotates iterable fields.
+ * Note that for any {@link Message} implementations it is enough to set item type to {@code Message.class}.
  */
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.FIELD)

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
index c2df045..dba043a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
@@ -55,6 +55,9 @@ import static org.jsr166.ConcurrentLinkedHashMap.QueuePolicy.*;
  * Grid communication manager.
  */
 public class GridIoManager extends GridManagerAdapter<CommunicationSpi<Serializable>> {
+    /** Empty array of message factories. */
+    public static final MessageFactory[] EMPTY = {};
+
     /** Max closed topics to store. */
     public static final int MAX_CLOSED_TOPICS = 10240;
 
@@ -224,7 +227,25 @@ public class GridIoManager extends GridManagerAdapter<CommunicationSpi<Serializa
             };
         }
 
-        msgFactory = new GridIoMessageFactory(ctx.plugins().extensions(MessageFactory.class));
+        MessageFactory[] msgs = ctx.plugins().extensions(MessageFactory.class);
+
+        if (msgs == null)
+            msgs = EMPTY;
+
+        MessageFactory qryMsgs = null;
+
+        try {
+            qryMsgs = U.newInstance( // TODO fix this dirty hack
+                "org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessageFactory");
+        }
+        catch (IgniteCheckedException e) {
+            // No-op.
+        }
+
+        if (qryMsgs != null)
+            msgs = F.concat(msgs, qryMsgs);
+
+        msgFactory = new GridIoMessageFactory(msgs);
 
         if (log.isDebugEnabled())
             log.debug(startInfo());

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index b82147b..5b7d84d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -595,6 +595,14 @@ public class GridIoMessageFactory implements MessageFactory {
 
                 break;
 
+            case 112:
+                msg = new GridCacheSqlQuery();
+
+                break;
+
+            // [-3..112] - this
+            // [120..123] - DR
+            // [-4..-21] - SQL
             default:
                 if (ext != null) {
                     for (MessageFactory factory : ext) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
index 2ee690a..0c1c822 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
@@ -17,16 +17,20 @@
 
 package org.apache.ignite.internal.processors.cache.query;
 
+import org.apache.ignite.*;
+import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.marshaller.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 
-import java.io.*;
+import java.nio.*;
 
 /**
  * Query.
  */
-public class GridCacheSqlQuery implements Externalizable {
+public class GridCacheSqlQuery implements Message {
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -34,18 +38,22 @@ public class GridCacheSqlQuery implements Externalizable {
     public static final Object[] EMPTY_PARAMS = {};
 
     /** */
-    String alias;
+    private String alias;
 
     /** */
     @GridToStringInclude
-    String qry;
+    private String qry;
 
     /** */
     @GridToStringInclude
-    Object[] params;
+    @GridDirectTransient
+    private Object[] params;
+
+    /** */
+    private byte[] paramsBytes;
 
     /**
-     * For {@link Externalizable}.
+     * For {@link Message}.
      */
     public GridCacheSqlQuery() {
         // No-op.
@@ -86,25 +94,116 @@ public class GridCacheSqlQuery implements Externalizable {
         return params;
     }
 
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        U.writeString(out, alias);
-        U.writeString(out, qry);
-        U.writeArray(out, params);
+    /**
+     * @param m Marshaller.
+     * @throws IgniteCheckedException If failed.
+     */
+    public void marshallParams(Marshaller m) throws IgniteCheckedException {
+        if (paramsBytes != null)
+            return;
+
+        assert params != null;
+
+        paramsBytes = m.marshal(params);
     }
 
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        alias = U.readString(in);
-        qry = U.readString(in);
-        params = U.readArray(in);
+    /**
+     * @param m Marshaller.
+     * @throws IgniteCheckedException If failed.
+     */
+    public void unmarshallParams(Marshaller m) throws IgniteCheckedException {
+        if (params != null)
+            return;
+
+        assert paramsBytes != null;
 
-        if (F.isEmpty(params))
-            params = EMPTY_PARAMS;
+        params = m.unmarshal(paramsBytes, null);
     }
 
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(GridCacheSqlQuery.class, this);
     }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeString("alias", alias))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeByteArray("paramsBytes", paramsBytes))
+                    return false;
+
+                writer.incrementState();
+
+            case 2:
+                if (!writer.writeString("qry", qry))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                alias = reader.readString("alias");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 1:
+                paramsBytes = reader.readByteArray("paramsBytes");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 2:
+                qry = reader.readString("qry");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return 112;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 3;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
index 11b2057..ce12a85 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
@@ -23,16 +23,12 @@ import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 
-import java.io.*;
 import java.util.*;
 
 /**
  * Two step map-reduce style query.
  */
-public class GridCacheTwoStepQuery implements Serializable {
-    /** */
-    private static final long serialVersionUID = 0L;
-
+public class GridCacheTwoStepQuery {
     /** */
     public static final int DFLT_PAGE_SIZE = 1000;
 
@@ -95,7 +91,7 @@ public class GridCacheTwoStepQuery implements Serializable {
      * @return Map queries.
      */
     public Collection<GridCacheSqlQuery> mapQueries() {
-        return new ArrayList<>(mapQrys.values()); // Copy to make it Serializable.
+        return mapQrys.values();
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
index fb8d35c..b1c3970 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
@@ -26,6 +26,7 @@ import org.apache.ignite.internal.processors.cache.query.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.apache.ignite.spi.indexing.*;
 import org.jetbrains.annotations.*;
 
@@ -224,4 +225,11 @@ public interface GridQueryIndexing {
      * @return Backup filter.
      */
     public IndexingQueryFilter backupFilter();
+
+    /**
+     * Gets message factory.
+     *
+     * @return Message factory.
+     */
+    public MessageFactory messageFactory();
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 5111b99..7a3cb68 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -24,6 +24,7 @@ import org.apache.ignite.cache.query.annotations.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.events.*;
 import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.managers.communication.*;
 import org.apache.ignite.internal.processors.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.cache.query.*;
@@ -35,6 +36,7 @@ import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.internal.util.worker.*;
 import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.apache.ignite.spi.indexing.*;
 import org.jetbrains.annotations.*;
 import org.jsr166.*;
@@ -650,6 +652,13 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * @return Message factory for {@link GridIoManager}.
+     */
+    public MessageFactory messageFactory() {
+        return idx == null ? null : idx.messageFactory();
+    }
+
+    /**
      * Closeable iterator.
      */
     private static interface ClIter<X> extends AutoCloseable, Iterator<X> {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryNextPageResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryNextPageResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryNextPageResponse.java
index b7b6f4c..4fdc027 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryNextPageResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryNextPageResponse.java
@@ -23,6 +23,7 @@ import org.apache.ignite.plugin.extensions.communication.*;
 
 import java.io.*;
 import java.nio.*;
+import java.util.*;
 
 /**
  * Next page response.
@@ -44,11 +45,15 @@ public class GridQueryNextPageResponse implements Message {
     private int allRows;
 
     /** */
-    private byte[] rows;
+    private int cols;
+
+    /** */
+    @GridDirectCollection(Message.class)
+    private Collection<Message> vals;
 
     /** */
     @GridDirectTransient
-    private transient Object plainRows;
+    private transient Collection<?> plainRows;
 
     /**
      * For {@link Externalizable}.
@@ -62,18 +67,21 @@ public class GridQueryNextPageResponse implements Message {
      * @param qry Query.
      * @param page Page.
      * @param allRows All rows count.
-     * @param rows Rows.
+     * @param cols Number of columns in row.
+     * @param vals Values for rows in this page added sequentially.
      * @param plainRows Not marshalled rows for local node.
      */
-    public GridQueryNextPageResponse(long qryReqId, int qry, int page, int allRows,
-        byte[] rows, Object plainRows) {
-        assert rows != null ^ plainRows != null;
+    public GridQueryNextPageResponse(long qryReqId, int qry, int page, int allRows, int cols,
+        Collection<Message> vals, Collection<?> plainRows) {
+        assert vals != null ^ plainRows != null;
+        assert cols > 0 : cols;
 
         this.qryReqId = qryReqId;
         this.qry = qry;
         this.page = page;
         this.allRows = allRows;
-        this.rows = rows;
+        this.cols = cols;
+        this.vals = vals;
         this.plainRows = plainRows;
     }
 
@@ -106,16 +114,23 @@ public class GridQueryNextPageResponse implements Message {
     }
 
     /**
-     * @return Rows.
+     * @return Columns in row.
      */
-    public byte[] rows() {
-        return rows;
+    public int columns() {
+        return cols;
+    }
+
+    /**
+     * @return Values.
+     */
+    public Collection<Message> values() {
+        return vals;
     }
 
     /**
      * @return Plain rows.
      */
-    public Object plainRows() {
+    public Collection<?> plainRows() {
         return plainRows;
     }
 
@@ -143,29 +158,34 @@ public class GridQueryNextPageResponse implements Message {
                 writer.incrementState();
 
             case 1:
-                if (!writer.writeInt("page", page))
+                if (!writer.writeInt("cols", cols))
                     return false;
 
                 writer.incrementState();
 
             case 2:
-                if (!writer.writeInt("qry", qry))
+                if (!writer.writeInt("page", page))
                     return false;
 
                 writer.incrementState();
 
             case 3:
-                if (!writer.writeLong("qryReqId", qryReqId))
+                if (!writer.writeInt("qry", qry))
                     return false;
 
                 writer.incrementState();
 
             case 4:
-                if (!writer.writeByteArray("rows", rows))
+                if (!writer.writeLong("qryReqId", qryReqId))
                     return false;
 
                 writer.incrementState();
 
+            case 5:
+                if (!writer.writeCollection("vals", vals, MessageCollectionItemType.MSG))
+                    return false;
+
+                writer.incrementState();
         }
 
         return true;
@@ -188,7 +208,7 @@ public class GridQueryNextPageResponse implements Message {
                 reader.incrementState();
 
             case 1:
-                page = reader.readInt("page");
+                cols = reader.readInt("cols");
 
                 if (!reader.isLastRead())
                     return false;
@@ -196,7 +216,7 @@ public class GridQueryNextPageResponse implements Message {
                 reader.incrementState();
 
             case 2:
-                qry = reader.readInt("qry");
+                page = reader.readInt("page");
 
                 if (!reader.isLastRead())
                     return false;
@@ -204,7 +224,7 @@ public class GridQueryNextPageResponse implements Message {
                 reader.incrementState();
 
             case 3:
-                qryReqId = reader.readLong("qryReqId");
+                qry = reader.readInt("qry");
 
                 if (!reader.isLastRead())
                     return false;
@@ -212,7 +232,15 @@ public class GridQueryNextPageResponse implements Message {
                 reader.incrementState();
 
             case 4:
-                rows = reader.readByteArray("rows");
+                qryReqId = reader.readLong("qryReqId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 5:
+                vals = reader.readCollection("vals", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
                     return false;
@@ -231,6 +259,6 @@ public class GridQueryNextPageResponse implements Message {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 5;
+        return 6;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryRequest.java
index b4c6668..3d3bcf9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryRequest.java
@@ -22,7 +22,6 @@ import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.query.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.marshaller.*;
 import org.apache.ignite.plugin.extensions.communication.*;
 
 import java.nio.*;
@@ -46,12 +45,9 @@ public class GridQueryRequest implements Message {
 
     /** */
     @GridToStringInclude
-    @GridDirectTransient
+    @GridDirectCollection(GridCacheSqlQuery.class)
     private Collection<GridCacheSqlQuery> qrys;
 
-    /** */
-    private byte[] qrysBytes;
-
     /**
      * Default constructor.
      */
@@ -64,17 +60,13 @@ public class GridQueryRequest implements Message {
      * @param pageSize Page size.
      * @param space Space.
      * @param qrys Queries.
-     * @param qrysBytes Marshalled queries.
      */
-    public GridQueryRequest(long reqId, int pageSize, String space, Collection<GridCacheSqlQuery> qrys, byte[] qrysBytes) {
+    public GridQueryRequest(long reqId, int pageSize, String space, Collection<GridCacheSqlQuery> qrys) {
         this.reqId = reqId;
         this.pageSize = pageSize;
         this.space = space;
 
-        assert qrysBytes != null;
-
         this.qrys = qrys;
-        this.qrysBytes = qrysBytes;
     }
 
     /**
@@ -101,10 +93,7 @@ public class GridQueryRequest implements Message {
     /**
      * @return Queries.
      */
-    public Collection<GridCacheSqlQuery> queries(Marshaller m) throws IgniteCheckedException {
-        if (qrys == null && qrysBytes != null)
-            qrys = m.unmarshal(qrysBytes, null);
-
+    public Collection<GridCacheSqlQuery> queries() throws IgniteCheckedException {
         return qrys;
     }
 
@@ -132,7 +121,7 @@ public class GridQueryRequest implements Message {
                 writer.incrementState();
 
             case 1:
-                if (!writer.writeByteArray("qrysBytes", qrysBytes))
+                if (!writer.writeCollection("qrys", qrys, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
@@ -171,7 +160,7 @@ public class GridQueryRequest implements Message {
                 reader.incrementState();
 
             case 1:
-                qrysBytes = reader.readByteArray("qrysBytes");
+                qrys = reader.readCollection("qrys", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
                     return false;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 46e2d5c..01eb855 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -31,6 +31,7 @@ import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.processors.query.h2.opt.*;
 import org.apache.ignite.internal.processors.query.h2.sql.*;
 import org.apache.ignite.internal.processors.query.h2.twostep.*;
+import org.apache.ignite.internal.processors.query.h2.twostep.msg.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.internal.util.offheap.unsafe.*;
@@ -39,6 +40,7 @@ import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.marshaller.*;
 import org.apache.ignite.marshaller.jdk.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.apache.ignite.resources.*;
 import org.apache.ignite.spi.*;
 import org.apache.ignite.spi.indexing.*;
@@ -1346,6 +1348,11 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         };
     }
 
+    /** {@inheritDoc} */
+    @Override public MessageFactory messageFactory() {
+        return new GridH2ValueMessageFactory();
+    }
+
     /**
      * Wrapper to store connection and flag is schema set or not.
      */
@@ -1965,7 +1972,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 CacheObjectContext coctx = objectContext(schema.spaceName);
 
                 if (type == Value.JAVA_OBJECT)
-                    return new ValueCacheObject(coctx, co);
+                    return new GridH2ValueCacheObject(coctx, co);
 
                 obj = co.value(coctx, false);
             }
@@ -2103,147 +2110,4 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             return new GridH2KeyValueRowOffheap(this, ptr);
         }
     }
-
-    /**
-     * Replacement for {@link ValueJavaObject}.
-     * Note that after serialization/deserialization it will become {@link ValueJavaObject}.
-     */
-    private static class ValueCacheObject extends Value {
-        /** */
-        private CacheObject obj;
-
-        /** */
-        private CacheObjectContext coctx;
-
-        /**
-         * @param coctx Cache object context.
-         * @param obj Object.
-         */
-        ValueCacheObject(CacheObjectContext coctx, CacheObject obj) {
-            assert obj != null;
-
-            this.obj = obj;
-            this.coctx = coctx; // Allowed to be null in tests.
-        }
-
-        /** {@inheritDoc} */
-        @Override public String getSQL() {
-            throw new UnsupportedOperationException();
-        }
-
-        /** {@inheritDoc} */
-        @Override public int getType() {
-            return Value.JAVA_OBJECT;
-        }
-
-        /** {@inheritDoc} */
-        @Override public long getPrecision() {
-            return 0;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int getDisplaySize() {
-            return 64;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String getString() {
-            return getObject().toString();
-        }
-
-        /** {@inheritDoc} */
-        @Override public byte[] getBytes() {
-            return Utils.cloneByteArray(getBytesNoCopy());
-        }
-
-        /** {@inheritDoc} */
-        @Override public byte[] getBytesNoCopy() {
-            if (obj.type() == CacheObject.TYPE_REGULAR) {
-                // Result must be the same as `marshaller.marshall(obj.value(coctx, false));`
-                try {
-                    return obj.valueBytes(coctx);
-                }
-                catch (IgniteCheckedException e) {
-                    throw DbException.convert(e);
-                }
-            }
-
-            // For portables and byte array cache object types.
-            return Utils.serialize(obj.value(coctx, false), null);
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object getObject() {
-            return obj.value(coctx, false);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
-            prep.setObject(parameterIndex, getObject(), Types.JAVA_OBJECT);
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings("unchecked")
-        @Override protected int compareSecure(Value v, CompareMode mode) {
-            Object o1 = getObject();
-            Object o2 = v.getObject();
-
-            boolean o1Comparable = o1 instanceof Comparable;
-            boolean o2Comparable = o2 instanceof Comparable;
-
-            if (o1Comparable && o2Comparable &&
-                Utils.haveCommonComparableSuperclass(o1.getClass(), o2.getClass())) {
-                Comparable<Object> c1 = (Comparable<Object>)o1;
-
-                return c1.compareTo(o2);
-            }
-
-            // Group by types.
-            if (o1.getClass() != o2.getClass()) {
-                if (o1Comparable != o2Comparable)
-                    return o1Comparable ? -1 : 1;
-
-                return o1.getClass().getName().compareTo(o2.getClass().getName());
-            }
-
-            // Compare hash codes.
-            int h1 = hashCode();
-            int h2 = v.hashCode();
-
-            if (h1 == h2) {
-                if (o1.equals(o2))
-                    return 0;
-
-                return Utils.compareNotNullSigned(getBytesNoCopy(), v.getBytesNoCopy());
-            }
-
-            return h1 > h2 ? 1 : -1;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return getObject().hashCode();
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object other) {
-            if (!(other instanceof Value))
-                return false;
-
-            Value otherVal = (Value)other;
-
-            return otherVal.getType() == Value.JAVA_OBJECT
-                && getObject().equals(otherVal.getObject());
-        }
-
-        /** {@inheritDoc} */
-        @Override public Value convertPrecision(long precision, boolean force) {
-            return this;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int getMemory() {
-            return 0;
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
new file mode 100644
index 0000000..0bb2a89
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
@@ -0,0 +1,160 @@
+package org.apache.ignite.internal.processors.query.h2.opt;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.*;
+import org.h2.message.*;
+import org.h2.util.*;
+import org.h2.value.*;
+
+import java.sql.*;
+
+/**
+ * H2 Value over {@link CacheObject}. Replacement for {@link ValueJavaObject}.
+ */
+public class GridH2ValueCacheObject extends Value {
+    /** */
+    private CacheObject obj;
+
+    /** */
+    private CacheObjectContext coctx;
+
+    /**
+     * @param coctx Cache object context.
+     * @param obj Object.
+     */
+    public GridH2ValueCacheObject(CacheObjectContext coctx, CacheObject obj) {
+        assert obj != null;
+
+        this.obj = obj;
+        this.coctx = coctx; // Allowed to be null in tests.
+    }
+
+    /**
+     * @return Cache object.
+     */
+    public CacheObject getCacheObject() {
+        return obj;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getSQL() {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getType() {
+        return Value.JAVA_OBJECT;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getPrecision() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getDisplaySize() {
+        return 64;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getString() {
+        return getObject().toString();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] getBytes() {
+        return Utils.cloneByteArray(getBytesNoCopy());
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] getBytesNoCopy() {
+        if (obj.type() == CacheObject.TYPE_REGULAR) {
+            // Result must be the same as `marshaller.marshall(obj.value(coctx, false));`
+            try {
+                return obj.valueBytes(coctx);
+            }
+            catch (IgniteCheckedException e) {
+                throw DbException.convert(e);
+            }
+        }
+
+        // For portables and byte array cache object types.
+        return Utils.serialize(obj.value(coctx, false), null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object getObject() {
+        return obj.value(coctx, false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
+        prep.setObject(parameterIndex, getObject(), Types.JAVA_OBJECT);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override protected int compareSecure(Value v, CompareMode mode) {
+        Object o1 = getObject();
+        Object o2 = v.getObject();
+
+        boolean o1Comparable = o1 instanceof Comparable;
+        boolean o2Comparable = o2 instanceof Comparable;
+
+        if (o1Comparable && o2Comparable &&
+            Utils.haveCommonComparableSuperclass(o1.getClass(), o2.getClass())) {
+            Comparable<Object> c1 = (Comparable<Object>)o1;
+
+            return c1.compareTo(o2);
+        }
+
+        // Group by types.
+        if (o1.getClass() != o2.getClass()) {
+            if (o1Comparable != o2Comparable)
+                return o1Comparable ? -1 : 1;
+
+            return o1.getClass().getName().compareTo(o2.getClass().getName());
+        }
+
+        // Compare hash codes.
+        int h1 = hashCode();
+        int h2 = v.hashCode();
+
+        if (h1 == h2) {
+            if (o1.equals(o2))
+                return 0;
+
+            return Utils.compareNotNullSigned(getBytesNoCopy(), v.getBytesNoCopy());
+        }
+
+        return h1 > h2 ? 1 : -1;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return getObject().hashCode();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object other) {
+        if (!(other instanceof Value))
+            return false;
+
+        Value otherVal = (Value)other;
+
+        return otherVal.getType() == Value.JAVA_OBJECT
+            && getObject().equals(otherVal.getObject());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value convertPrecision(long precision, boolean force) {
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getMemory() {
+        return 0;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
index 918a541..66b3636 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
@@ -30,6 +30,8 @@ import org.apache.ignite.internal.processors.query.h2.twostep.messages.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.marshaller.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.h2.jdbc.*;
 import org.h2.result.*;
 import org.h2.store.*;
@@ -44,6 +46,7 @@ import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
 
 import static org.apache.ignite.events.EventType.*;
+import static org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessageFactory.*;
 
 /**
  * Map query executor.
@@ -203,7 +206,14 @@ public class GridMapQueryExecutor {
         Collection<GridCacheSqlQuery> qrys;
 
         try {
-            qrys = req.queries(ctx.config().getMarshaller());
+            qrys = req.queries();
+
+            if (!node.isLocal()) {
+                Marshaller m = ctx.config().getMarshaller();
+
+                for (GridCacheSqlQuery qry : qrys)
+                    qry.unmarshallParams(m);
+            }
         }
         catch (IgniteCheckedException e) {
             throw new IgniteException(e);
@@ -344,7 +354,10 @@ public class GridMapQueryExecutor {
             boolean loc = node.isLocal();
 
             GridQueryNextPageResponse msg = new GridQueryNextPageResponse(qr.qryReqId, qry, page,
-                page == 0 ? res.rowCount : -1, loc ? null : marshallRows(rows), loc ? rows : null);
+                page == 0 ? res.rowCount : -1 ,
+                res.cols,
+                loc ? null : toMessages(rows, new ArrayList<Message>(res.cols)),
+                loc ? rows : null);
 
             if (loc)
                 h2.reduceQueryExecutor().onMessage(ctx.localNodeId(), msg);
@@ -510,6 +523,9 @@ public class GridMapQueryExecutor {
         private final UUID qrySrcNodeId;
 
         /** */
+        private final int cols;
+
+        /** */
         private int page;
 
         /** */
@@ -538,6 +554,7 @@ public class GridMapQueryExecutor {
             }
 
             rowCount = res.getRowCount();
+            cols = res.getVisibleColumnCount();
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java
index 407341e..2b5c895 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java
@@ -103,7 +103,7 @@ public abstract class GridMergeIndex extends BaseIndex {
      * @param page Page.
      */
     public final void addPage(GridResultPage page) {
-        int pageRowsCnt = page.rows().size();
+        int pageRowsCnt = page.rowsInPage();
 
         if (pageRowsCnt != 0)
             addPage0(page);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexUnsorted.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexUnsorted.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexUnsorted.java
index 93c9482..76a52e9 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexUnsorted.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexUnsorted.java
@@ -44,7 +44,7 @@ public class GridMergeIndexUnsorted extends GridMergeIndex {
 
     /** {@inheritDoc} */
     @Override protected void addPage0(GridResultPage page) {
-        if (!page.rows().isEmpty() || page.isLast() || queue.isEmpty())
+        if (page.rowsInPage() != 0 || page.isLast() || queue.isEmpty())
             queue.add(page);
     }
 
@@ -75,7 +75,7 @@ public class GridMergeIndexUnsorted extends GridMergeIndex {
 
                     fetchNextPage(page);
 
-                    iter = page.rows().iterator();
+                    iter = page.rows();
                 }
 
                 return true;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/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 7f42e0d..d7832f0 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
@@ -33,6 +33,7 @@ import org.apache.ignite.internal.processors.query.h2.twostep.messages.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.marshaller.*;
 import org.apache.ignite.plugin.extensions.communication.*;
 import org.h2.command.ddl.*;
 import org.h2.command.dml.Query;
@@ -317,8 +318,14 @@ public class GridReduceQueryExecutor {
         runs.put(qryReqId, r);
 
         try {
-            send(nodes, new GridQueryRequest(qryReqId, r.pageSize, space, qry.mapQueries(),
-                ctx.config().getMarshaller().marshal(qry.mapQueries())));
+            if (nodes.size() != 1 || !F.first(nodes).isLocal()) { // Marshall params for remotes.
+                Marshaller m = ctx.config().getMarshaller();
+
+                for (GridCacheSqlQuery mapQry : qry.mapQueries())
+                    mapQry.marshallParams(m);
+            }
+
+            send(nodes, new GridQueryRequest(qryReqId, r.pageSize, space, qry.mapQueries()));
 
             r.latch.await();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridResultPage.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridResultPage.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridResultPage.java
index 5f58b95..af1bb4f 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridResultPage.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridResultPage.java
@@ -19,10 +19,13 @@ package org.apache.ignite.internal.processors.query.h2.twostep;
 
 import org.apache.ignite.internal.processors.query.h2.twostep.messages.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.h2.value.*;
 
 import java.util.*;
 
+import static org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessageFactory.*;
+
 /**
  * Page result.
  */
@@ -34,11 +37,14 @@ public class GridResultPage {
     protected final GridQueryNextPageResponse res;
 
     /** */
-    private final Collection<Value[]> rows;
+    private final int rowsInPage;
 
     /** */
     private final boolean last;
 
+    /** */
+    private Iterator<Value[]> rows;
+
     /**
      * @param src Source.
      * @param res Response.
@@ -57,12 +63,48 @@ public class GridResultPage {
 
         // res == null means that it is a terminating dummy page for the given source node ID.
         if (res != null) {
-            Object plainRows = res.plainRows();
+            Collection<?> plainRows = res.plainRows();
+
+            if (plainRows != null) {
+                rowsInPage = plainRows.size();
+
+                rows = (Iterator<Value[]>)plainRows.iterator();
+            }
+            else {
+                final int cols = res.columns();
+
+                rowsInPage = res.values().size() / cols;
+
+                final Iterator<Message> valsIter = res.values().iterator();
+
+                rows = new Iterator<Value[]>() {
+                    /** */
+                    int rowIdx;
+
+                    @Override public boolean hasNext() {
+                        return rowIdx < rowsInPage;
+                    }
+
+                    @Override public Value[] next() {
+                        if (!hasNext())
+                            throw new NoSuchElementException();
+
+                        rowIdx++;
 
-            rows = plainRows != null ? (Collection<Value[]>)plainRows : GridMapQueryExecutor.unmarshallRows(res.rows());
+                        return fillArray(valsIter, new Value[cols], null); // TODO coctx
+                    }
+
+                    @Override public void remove() {
+                        throw new UnsupportedOperationException();
+                    }
+                };
+            }
+        }
+        else {
+            rowsInPage = 0;
+
+            rows = Collections.emptyIterator();
         }
-        else
-            rows = Collections.emptySet();
     }
 
     /**
@@ -73,10 +115,23 @@ public class GridResultPage {
     }
 
     /**
+     * @return Number on rows in this page.
+     */
+    public int rowsInPage() {
+        return rowsInPage;
+    }
+
+    /**
      * @return Rows.
      */
-    public Collection<Value[]> rows() {
-        return rows;
+    public Iterator<Value[]> rows() {
+        Iterator<Value[]> r = rows;
+
+        assert r != null;
+
+        rows = null;
+
+        return r;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Array.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Array.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Array.java
new file mode 100644
index 0000000..0354a93
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Array.java
@@ -0,0 +1,106 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+import java.util.*;
+
+import static org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessageFactory.*;
+
+/**
+ * H2 Array.
+ */
+public class GridH2Array extends GridH2ValueMessage {
+    /** */
+    @GridDirectCollection(Message.class)
+    private Collection<Message> x;
+
+    /**
+     *
+     */
+    public GridH2Array() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Array(Value val) {
+        assert val.getType() == Value.ARRAY : val.getType();
+
+        ValueArray arr = (ValueArray)val;
+
+        x = new ArrayList<>(arr.getList().length);
+
+        for (Value v : arr.getList())
+            x.add(toMessage(v));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        // TODO we need cache object context
+        return ValueArray.get(fillArray(x.iterator(), new Value[x.size()], null));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeCollection("x", x, MessageCollectionItemType.MSG))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readCollection("x", MessageCollectionItemType.MSG);
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -18;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Boolean.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Boolean.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Boolean.java
new file mode 100644
index 0000000..0cae9cd
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Boolean.java
@@ -0,0 +1,94 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Boolean.
+ */
+public class GridH2Boolean extends GridH2ValueMessage {
+    /** */
+    private boolean x;
+
+    /**
+     *
+     */
+    public GridH2Boolean() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Boolean(Value val) {
+        assert val.getType() == Value.BOOLEAN : val.getType();
+
+        x = val.getBoolean();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueBoolean.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeBoolean("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readBoolean("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -5;
+    }
+
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Byte.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Byte.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Byte.java
new file mode 100644
index 0000000..73fce14
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Byte.java
@@ -0,0 +1,95 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Byte.
+ */
+public class GridH2Byte extends GridH2ValueMessage {
+    /** */
+    private byte x;
+
+    /**
+     *
+     */
+    public GridH2Byte() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Byte(Value val) {
+        assert val.getType() == Value.BYTE : val.getType();
+
+        x = val.getByte();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueByte.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeByte("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readByte("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -6;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Bytes.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Bytes.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Bytes.java
new file mode 100644
index 0000000..e139da8
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Bytes.java
@@ -0,0 +1,95 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Bytes.
+ */
+public class GridH2Bytes extends GridH2ValueMessage {
+    /** */
+    private byte[] b;
+
+    /**
+     *
+     */
+    public GridH2Bytes() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Bytes(Value val) {
+        assert val.getType() == Value.BYTES : val.getType();
+
+        b = val.getBytesNoCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueBytes.getNoCopy(b);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeByteArray("b", b))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                b = reader.readByteArray("b");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -16;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Date.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Date.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Date.java
new file mode 100644
index 0000000..f6cef67
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Date.java
@@ -0,0 +1,97 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Date.
+ */
+public class GridH2Date extends GridH2ValueMessage {
+    /** */
+    private long date;
+
+    /**
+     *
+     */
+    public GridH2Date() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Date(Value val) {
+        assert val.getType() == Value.DATE : val.getType();
+
+        ValueDate d = (ValueDate)val;
+
+        date = d.getDateValue();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueDate.fromDateValue(date);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeLong("date", date))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                date = reader.readLong("date");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -14;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Decimal.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Decimal.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Decimal.java
new file mode 100644
index 0000000..b3b3adc
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Decimal.java
@@ -0,0 +1,95 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Decimal.
+ */
+public class GridH2Decimal extends GridH2ValueMessage {
+    /** */
+    private byte[] b;
+
+    /**
+     *
+     */
+    public GridH2Decimal() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Decimal(Value val) {
+        assert val.getType() == Value.DECIMAL : val.getType();
+
+        b = val.getBytesNoCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueBytes.getNoCopy(b).convertTo(Value.DECIMAL);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeByteArray("b", b))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                b = reader.readByteArray("b");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -10;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Double.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Double.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Double.java
new file mode 100644
index 0000000..eed3d87
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Double.java
@@ -0,0 +1,95 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Double.
+ */
+public class GridH2Double extends GridH2ValueMessage {
+    /** */
+    private double x;
+
+    /**
+     *
+     */
+    public GridH2Double() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Double(Value val) {
+        assert val.getType() == Value.DOUBLE : val.getType();
+
+        x = val.getDouble();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueDouble.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeDouble("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readDouble("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -11;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Float.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Float.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Float.java
new file mode 100644
index 0000000..8e860b5
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Float.java
@@ -0,0 +1,95 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Float.
+ */
+public class GridH2Float extends GridH2ValueMessage {
+    /** */
+    private float x;
+
+    /**
+     *
+     */
+    public GridH2Float() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Float(Value val) {
+        assert val.getType() == Value.FLOAT : val.getType();
+
+        x = val.getFloat();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueFloat.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeFloat("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readFloat("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -12;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Geometry.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Geometry.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Geometry.java
new file mode 100644
index 0000000..15a260a
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Geometry.java
@@ -0,0 +1,116 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.lang.reflect.*;
+import java.nio.*;
+
+/**
+ * H2 Geometry.
+ */
+public class GridH2Geometry extends GridH2ValueMessage {
+    /** */
+    private static final Method GEOMETRY_FROM_BYTES;
+
+    /**
+     * Initialize field.
+     */
+    static {
+        try {
+            GEOMETRY_FROM_BYTES = Class.forName("org.h2.value.ValueGeometry").getMethod("get", byte[].class);
+        }
+        catch (NoSuchMethodException | ClassNotFoundException e) {
+            throw new IllegalStateException("Check H2 version in classpath.");
+        }
+    }
+
+    /** */
+    private byte[] b;
+
+    /**
+     *
+     */
+    public GridH2Geometry() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Geometry(Value val) {
+        assert val.getType() == Value.GEOMETRY : val.getType();
+
+        b = val.getBytesNoCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        try {
+            return (Value)GEOMETRY_FROM_BYTES.invoke(null, new Object[]{b});
+        }
+        catch (IllegalAccessException | InvocationTargetException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeByteArray("b", b))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                b = reader.readByteArray("b");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -21;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Integer.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Integer.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Integer.java
new file mode 100644
index 0000000..7d2e80b
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Integer.java
@@ -0,0 +1,95 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Integer.
+ */
+public class GridH2Integer extends GridH2ValueMessage {
+    /** */
+    private int x;
+
+    /**
+     *
+     */
+    public GridH2Integer() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Integer(Value val) {
+        assert val.getType() == Value.INT : val.getType();
+
+        x = val.getInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueInt.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeInt("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readInt("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -8;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2JavaObject.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2JavaObject.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2JavaObject.java
new file mode 100644
index 0000000..b7da4f1
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2JavaObject.java
@@ -0,0 +1,95 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Java Object.
+ */
+public class GridH2JavaObject extends GridH2ValueMessage {
+    /** */
+    private byte[] b;
+
+    /**
+     *
+     */
+    public GridH2JavaObject() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2JavaObject(Value val) {
+        assert val.getType() == Value.JAVA_OBJECT : val.getType();
+
+        b = val.getBytesNoCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueJavaObject.getNoCopy(null, b, null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeByteArray("b", b))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                b = reader.readByteArray("b");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -19;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Long.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Long.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Long.java
new file mode 100644
index 0000000..7d850b5
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Long.java
@@ -0,0 +1,95 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Long.
+ */
+public class GridH2Long extends GridH2ValueMessage {
+    /** */
+    private long x;
+
+    /**
+     *
+     */
+    public GridH2Long() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Long(Value val) {
+        assert val.getType() == Value.LONG : val.getType();
+
+        x = val.getLong();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueLong.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeLong("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readLong("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -9;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Null.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Null.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Null.java
new file mode 100644
index 0000000..7968998
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Null.java
@@ -0,0 +1,66 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * Message for {@link Value#NULL}.
+ */
+public class GridH2Null extends GridH2ValueMessage {
+    /** */
+    public static GridH2Null INSTANCE = new GridH2Null();
+
+    /**
+     * Disallow new instance creation.
+     */
+    private GridH2Null() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueNull.INSTANCE;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -4;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 0;
+    }
+}


Mime
View raw message