ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: sqk-store Compare values without unmarshalling.
Date Thu, 04 Feb 2016 14:31:42 GMT
Repository: ignite
Updated Branches:
  refs/heads/sql-store-cmp [created] 6a6f5d14e


sqk-store Compare values without unmarshalling.


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

Branch: refs/heads/sql-store-cmp
Commit: 6a6f5d14e01c249beed1784148ca47074fc92b73
Parents: 155799a
Author: sboikov <sboikov@gridgain.com>
Authored: Thu Feb 4 17:31:08 2016 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Thu Feb 4 17:31:08 2016 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/binary/BinaryField.java   |   7 ++
 .../ignite/internal/binary/BinaryFieldImpl.java |  54 ++++++++
 .../processors/query/GridQueryProcessor.java    | 126 +++++++++++++++++++
 .../processors/query/GridQueryProperty.java     |  13 ++
 .../processors/query/h2/IgniteH2Indexing.java   |  10 ++
 .../query/h2/opt/GridH2AbstractKeyValueRow.java |   2 +-
 .../query/h2/opt/GridH2RowDescriptor.java       |  13 +-
 .../processors/query/h2/opt/GridH2Utils.java    |   9 ++
 .../h2/GridIndexingSpiAbstractSelfTest.java     |  11 +-
 9 files changed, 241 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6a6f5d14/modules/core/src/main/java/org/apache/ignite/binary/BinaryField.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryField.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryField.java
index 35aa191..b85caed 100644
--- a/modules/core/src/main/java/org/apache/ignite/binary/BinaryField.java
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryField.java
@@ -43,4 +43,11 @@ public interface BinaryField {
      * @return Value.
      */
     public <T> T value(BinaryObject obj);
+
+    /**
+     * @param addr Marshalled object address.
+     * @param len Marshalled data length.
+     * @return Field address.
+     */
+    public long fieldAddress(long addr, int len);
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a6f5d14/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
index 4b59904..706bd39 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
@@ -26,6 +26,8 @@ import java.util.Date;
 import java.util.UUID;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.internal.binary.streams.BinaryByteBufferInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryOffheapInputStream;
+import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.binary.BinaryObject;
@@ -103,6 +105,58 @@ public class BinaryFieldImpl implements BinaryFieldEx {
     }
 
     /** {@inheritDoc} */
+    @Override public long fieldAddress(long addr, int len) {
+        int typeId = GridUnsafe.unsafe().getInt(addr + GridBinaryMarshaller.TYPE_ID_POS);
+
+        if (typeId != this.typeId) {
+            throw new BinaryObjectException("Failed to get field because type ID of passed
object differs" +
+                " from type ID this " + BinaryField.class.getSimpleName() + " belongs to
[expected=" + this.typeId +
+                ", actual=" + typeId + ']');
+        }
+
+        int schemaId = GridUnsafe.unsafe().getInt(addr + GridBinaryMarshaller.SCHEMA_ID_POS);
+
+        BinarySchema schema = schemas.schema(schemaId);
+
+        if (schema == null) {
+            BinaryOffheapInputStream in = new BinaryOffheapInputStream(addr, len);
+
+            BinaryObjectExImpl obj = (BinaryObjectExImpl)BinaryUtils.unmarshal(in, ctx, null);
+
+            assert obj != null;
+
+            schema = obj.createSchema();
+        }
+
+        assert schema != null;
+
+        int order = schema.order(fieldId);
+
+        if (order == BinarySchema.ORDER_NOT_FOUND)
+            return -1L;
+
+        int schemaOff = BinaryPrimitives.readInt(addr, GridBinaryMarshaller.SCHEMA_OR_RAW_OFF_POS);
+
+        short flags = BinaryPrimitives.readShort(addr, GridBinaryMarshaller.FLAGS_POS);
+
+        int fieldIdLen = BinaryUtils.isCompactFooter(flags) ? 0 : BinaryUtils.FIELD_ID_LEN;
+        int fieldOffLen = BinaryUtils.fieldOffsetLength(flags);
+
+        int fieldOffPos = schemaOff + order * (fieldIdLen + fieldOffLen) + fieldIdLen;
+
+        int fieldPos;
+
+        if (fieldOffLen == BinaryUtils.OFFSET_1)
+            fieldPos = ((int)BinaryPrimitives.readByte(addr, fieldOffPos) & 0xFF);
+        else if (fieldOffLen == BinaryUtils.OFFSET_2)
+            fieldPos = ((int)BinaryPrimitives.readShort(addr, fieldOffPos) & 0xFFFF);
+        else
+            fieldPos = BinaryPrimitives.readInt(addr, fieldOffPos);
+
+        return addr + fieldPos;
+    }
+
+    /** {@inheritDoc} */
     @Override public boolean writeField(BinaryObject obj, ByteBuffer buf) {
         BinaryObjectExImpl obj0 = (BinaryObjectExImpl)obj;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a6f5d14/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 cb4be3a..be382c3 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
@@ -35,7 +35,11 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.events.CacheQueryExecutedEvent;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.binary.BinaryContext;
 import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.streams.BinaryOffheapInputStream;
 import org.apache.ignite.internal.processors.GridProcessorAdapter;
 import org.apache.ignite.internal.processors.cache.CacheEntryImpl;
 import org.apache.ignite.internal.processors.cache.CacheObject;
@@ -48,7 +52,9 @@ import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture;
 import org.apache.ignite.internal.processors.cache.query.CacheQueryType;
 import org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
 import org.apache.ignite.internal.util.GridSpinBusyLock;
+import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.future.GridCompoundFuture;
 import org.apache.ignite.internal.util.future.GridFinishedFuture;
 import org.apache.ignite.internal.util.lang.GridCloseableIterator;
@@ -1880,6 +1886,16 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         }
 
         /** {@inheritDoc} */
+        @Override public long valueAddress(long keyAddr, int keyLen, long valAddr, int valLen)
{
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean keyProperty() {
+            return false;
+        }
+
+        /** {@inheritDoc} */
         @Override public Object value(Object key, Object val) throws IgniteCheckedException
{
             Object x = unwrap(this.key ? key : val);
 
@@ -1972,6 +1988,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         /** Flag indicating that we already tried to take a field. */
         private volatile boolean fieldTaken;
 
+        /** */
+        private BinaryContext binaryCtx;
+
         /**
          * Constructor.
          *
@@ -1984,6 +2003,85 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             this.alias = F.isEmpty(alias) ? propName : alias;
             this.parent = parent;
             this.type = type;
+
+            IgniteCacheObjectProcessor proc = ctx.cacheObjects();
+
+            if (proc instanceof CacheObjectBinaryProcessorImpl)
+                binaryCtx = ((CacheObjectBinaryProcessorImpl)proc).binaryContext();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean keyProperty() {
+            int isKeyProp0 = isKeyProp;
+
+            assert isKeyProp0 != 0;
+
+            return isKeyProp0 == 1;
+        }
+
+        /** {@inheritDoc} */
+        @Override public long valueAddress(long keyAddr, int keyLen, long valAddr, int valLen)
throws IgniteCheckedException {
+            if (binaryCtx == null)
+                throw new UnsupportedOperationException("BinaryObjects are not enabled.");
+
+            int isKeyProp0 = isKeyProp;
+
+            if (isKeyProp0 == 0) {
+                // Key is allowed to be a non-binary object here.
+                // We check key before value consistently with ClassProperty.
+                if (hasField(keyAddr, keyLen, propName))
+                    isKeyProp = isKeyProp0 = 1;
+                else if (hasField(valAddr, valLen, propName))
+                    isKeyProp = isKeyProp0 = -1;
+                else {
+                    U.warn(log, "Neither key nor value have property [propName=" + propName
+ "]");
+
+                    return -1L;
+                }
+            }
+
+            long addr;
+            int len;
+
+            if (isKeyProp0 == 1) {
+                addr = keyAddr;
+                len = keyLen;
+            }
+            else {
+                addr = valAddr;
+                len = valLen;
+            }
+
+            BinaryField field = binaryField(addr);
+
+            if (field != null)
+                return field.fieldAddress(addr, len);
+
+            // TODO: try to get address from object.
+
+            return -1L;
+        }
+
+        /**
+         * @param addr Marshalled object address.
+         * @param len Marshalled data length.
+         * @param fieldName Field name.
+         * @return {@code True} if object has field with given name.
+         * @throws IgniteCheckedException If failed.
+         */
+        private boolean hasField(long addr, int len, String fieldName) throws IgniteCheckedException
{
+            byte type = GridUnsafe.unsafe().getByte(addr);
+
+            if (type != GridBinaryMarshaller.BINARY_OBJ)
+                return false;
+
+            BinaryOffheapInputStream in = new BinaryOffheapInputStream(addr, len);
+
+            BinaryObject obj = (BinaryObject)BinaryUtils.unmarshal(in, binaryCtx, null);
+
+            assert obj != null;
+
+            return obj.hasField(fieldName);
         }
 
         /** {@inheritDoc} */
@@ -2031,6 +2129,34 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         /**
          * Get binary field for the property.
          *
+         * @param addr Marshalled object address.
+         * @return Binary field.
+         */
+        private BinaryField binaryField(long addr) {
+            BinaryField field0 = field;
+
+            if (field0 == null && !fieldTaken) {
+                int typeId = GridUnsafe.unsafe().getInt(addr + GridBinaryMarshaller.TYPE_ID_POS);
+
+                BinaryType type = binaryCtx.metadata(typeId);
+
+                if (type != null) {
+                    field0 = type.field(propName);
+
+                    assert field0 != null;
+
+                    field = field0;
+                }
+
+                fieldTaken = true;
+            }
+
+            return field0;
+        }
+
+        /**
+         * Get binary field for the property.
+         *
          * @param obj Target object.
          * @return Binary field.
          */

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a6f5d14/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProperty.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProperty.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProperty.java
index d623d25..6e600a1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProperty.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProperty.java
@@ -42,4 +42,17 @@ public abstract class GridQueryProperty {
      * @return Class member type.
      */
     public abstract Class<?> type();
+
+    /**
+     * @param keyAddr Marshaled key address.
+     * @param valAddr Marshalled value address.
+     * @return Value address of -1 if property not found.
+     * @throws IgniteCheckedException If failed.
+     */
+    public abstract long valueAddress(long keyAddr, int keyLen, long valAddr, int valLen)
throws IgniteCheckedException;
+
+    /**
+     * @return {@code True} if property belongs to cache key.
+     */
+    public abstract boolean keyProperty();
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a6f5d14/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 c2aee58..60c9a9f 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
@@ -2521,6 +2521,16 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         }
 
         /** {@inheritDoc} */
+        @Override public int keyType() {
+            return keyType;
+        }
+
+        /** {@inheritDoc} */
+        @Override public GridQueryProperty property(int col) {
+            return props[col];
+        }
+
+        /** {@inheritDoc} */
         @Override public int valueType() {
             return valType;
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a6f5d14/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2AbstractKeyValueRow.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2AbstractKeyValueRow.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2AbstractKeyValueRow.java
index ca5442a..d366a39 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2AbstractKeyValueRow.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2AbstractKeyValueRow.java
@@ -40,7 +40,7 @@ import org.jetbrains.annotations.Nullable;
  */
 public abstract class GridH2AbstractKeyValueRow extends GridH2Row {
     /** */
-    private static final int DEFAULT_COLUMNS_COUNT = 2;
+    public static final int DEFAULT_COLUMNS_COUNT = 2;
 
     /** Key column. */
     public static final int KEY_COL = 0;

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a6f5d14/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
index de9368a..96644ae 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
@@ -19,8 +19,8 @@ package org.apache.ignite.internal.processors.query.h2.opt;
 
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.processors.query.GridQueryProperty;
 import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
 import org.apache.ignite.internal.util.offheap.unsafe.GridOffHeapSmartPointerFactory;
 import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeGuard;
@@ -58,6 +58,17 @@ public interface GridH2RowDescriptor extends GridOffHeapSmartPointerFactory<Grid
     public Object readFromSwap(Object key) throws IgniteCheckedException;
 
     /**
+     * @return Key type.
+     */
+    public int keyType();
+
+    /**
+     * @param col Column index.
+     * @return Property descriptor.
+     */
+    public GridQueryProperty property(int col);
+
+    /**
      * @return Value type.
      */
     public int valueType();

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a6f5d14/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Utils.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Utils.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Utils.java
index aafcfcc..54f2014 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Utils.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Utils.java
@@ -78,6 +78,15 @@ public class GridH2Utils {
         return ValueTimestamp.fromDateValueAndNanos(dateValue, nanos);
     }
 
+    public static long dateValueFromDate(long ms) {
+        Calendar calendar = getLocalCalendar();
+
+        calendar.clear();
+        calendar.setTimeInMillis(ms);
+
+        return dateValueFromCalendar(calendar);
+    }
+
     /**
      * Calculate the nanoseconds since midnight from a given calendar.
      *

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a6f5d14/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
index b37055d..0040cb6 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
@@ -518,10 +518,17 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
                     return name;
                 }
 
-                @Override
-                public Class<?> type() {
+                @Override public Class<?> type() {
                     return Object.class;
                 }
+
+                @Override public long valueAddress(long keyAddr, int keyLen, long valAddr,
int valLen) {
+                    throw new UnsupportedOperationException();
+                }
+
+                @Override public boolean keyProperty() {
+                    return false;
+                }
             };
         }
 


Mime
View raw message