ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [23/37] ignite git commit: Fixed Visor queries for BinaryObjects.
Date Thu, 05 Jan 2017 09:23:56 GMT
Fixed Visor queries for BinaryObjects.


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

Branch: refs/heads/ignite-2.0
Commit: 5769f44367cae5908cd291f226e9fccd68fe1c39
Parents: 9273e51
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Tue Dec 27 15:14:13 2016 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Tue Dec 27 15:14:13 2016 +0700

----------------------------------------------------------------------
 .../query/VisorQueryScanSubstringFilter.java    |  5 +-
 .../internal/visor/query/VisorQueryUtils.java   | 60 ++++++++++++++++++++
 2 files changed, 63 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5769f443/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryScanSubstringFilter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryScanSubstringFilter.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryScanSubstringFilter.java
index 43eb6dd..171698b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryScanSubstringFilter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryScanSubstringFilter.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.visor.query;
 
+import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.lang.IgniteBiPredicate;
 
 /**
@@ -52,8 +53,8 @@ public class VisorQueryScanSubstringFilter implements IgniteBiPredicate<Object,
      * @return {@code true} when string presentation of key or value contain specified string.
      */
     @Override public boolean apply(Object key, Object val) {
-        String k = key.toString();
-        String v = val.toString();
+        String k = key instanceof BinaryObject ? VisorQueryUtils.binaryToString((BinaryObject)key)
: key.toString();
+        String v = val instanceof BinaryObject ? VisorQueryUtils.binaryToString((BinaryObject)val)
: val.toString();
 
         if (caseSensitive)
             return k.contains(ptrn) || v.contains(ptrn);

http://git-wip-us.apache.org/repos/asf/ignite/blob/5769f443/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
index 0b8cf83..5faeac0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
@@ -25,7 +25,13 @@ import java.util.Collection;
 import java.util.Date;
 import java.util.List;
 import javax.cache.Cache;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.SB;
 
 /**
  * Contains utility methods for Visor query tasks and jobs.
@@ -77,12 +83,19 @@ public class VisorQueryUtils {
     private static String valueOf(Object o) {
         if (o == null)
             return "null";
+
         if (o instanceof byte[])
             return "size=" + ((byte[])o).length;
+
         if (o instanceof Byte[])
             return "size=" + ((Byte[])o).length;
+
         if (o instanceof Object[])
             return "size=" + ((Object[])o).length + ", values=[" + mkString((Object[])o,
120) + "]";
+
+        if (o instanceof BinaryObject)
+            return binaryToString((BinaryObject)o);
+
         return o.toString();
     }
 
@@ -168,6 +181,51 @@ public class VisorQueryUtils {
     }
 
     /**
+     * Convert Binary object to string.
+     *
+     * @param obj Binary object.
+     * @return String representation of Binary object.
+     */
+    public static String binaryToString(BinaryObject obj) {
+        int hash = obj.hashCode();
+
+        if (obj instanceof BinaryObjectEx) {
+            BinaryObjectEx objEx = (BinaryObjectEx)obj;
+
+            BinaryType meta;
+
+            try {
+                meta = ((BinaryObjectEx)obj).rawType();
+            }
+            catch (BinaryObjectException ignore) {
+                meta = null;
+            }
+
+            if (meta != null) {
+                SB buf = new SB(meta.typeName());
+
+                if (meta.fieldNames() != null) {
+                    buf.a(" [hash=").a(hash);
+
+                    for (String name : meta.fieldNames()) {
+                        Object val = objEx.field(name);
+
+                        buf.a(", ").a(name).a('=').a(val);
+                    }
+
+                    buf.a(']');
+
+                    return buf.toString();
+                }
+            }
+        }
+
+        return S.toString(obj.getClass().getSimpleName(),
+            "hash", hash, false,
+            "typeId", obj.type().typeId(), true);
+    }
+
+    /**
      * Collects rows from sql query future, first time creates meta and column names arrays.
      *
      * @param cur Query cursor to fetch rows from.
@@ -193,6 +251,8 @@ public class VisorQueryUtils {
                     row[i] = null;
                 else if (isKnownType(o))
                     row[i] = o;
+                else if (o instanceof BinaryObject)
+                    row[i] = binaryToString((BinaryObject)o);
                 else
                     row[i] = o.getClass().isArray() ? "binary" : o.toString();
             }


Mime
View raw message