You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by ti...@apache.org on 2012/07/08 10:37:09 UTC

svn commit: r1358704 - in /incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic: XSBinaryPointable.java XSDecimalPointable.java XSDurationPointable.java XSQNamePointable.java

Author: tillw
Date: Sun Jul  8 08:37:08 2012
New Revision: 1358704

URL: http://svn.apache.org/viewvc?rev=1358704&view=rev
Log:
add Pointables for Binary, Decimal, Duration, and QName as attached to VXQUERY-44 

Added:
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSBinaryPointable.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSQNamePointable.java
Modified:
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDurationPointable.java

Added: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSBinaryPointable.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSBinaryPointable.java?rev=1358704&view=auto
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSBinaryPointable.java (added)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSBinaryPointable.java Sun Jul  8 08:37:08 2012
@@ -0,0 +1,57 @@
+package org.apache.vxquery.datamodel.accessors.atomic;
+
+import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
+import edu.uci.ics.hyracks.data.std.api.AbstractPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointableFactory;
+
+public class XSBinaryPointable extends AbstractPointable {
+    public static final ITypeTraits TYPE_TRAITS = new ITypeTraits() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public boolean isFixedLength() {
+            return false;
+        }
+
+        @Override
+        public int getFixedLength() {
+            return 0;
+        }
+    };
+
+    public static final IPointableFactory FACTORY = new IPointableFactory() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public IPointable createPointable() {
+            return new XSBinaryPointable();
+        }
+
+        @Override
+        public ITypeTraits getTypeTraits() {
+            return TYPE_TRAITS;
+        }
+    };
+
+    /**
+     * Gets the length of the binary value in bytes.
+     * 
+     * @return length of binary value in bytes
+     */
+    public int getBinaryLength() {
+        return getBinaryLength(bytes, start);
+    }
+
+    public static int getBinaryLength(byte[] b, int s) {
+        return ((b[s] & 0xff) << 8) + ((b[s + 1] & 0xff) << 0);
+    }
+
+    public int getBinaryStart() {
+        return getBinaryStart(start);
+    }
+
+    public static int getBinaryStart(int start) {
+        return start + 2;
+    }
+}

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java?rev=1358704&r1=1358703&r2=1358704&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java Sun Jul  8 08:37:08 2012
@@ -1,22 +1,180 @@
 package org.apache.vxquery.datamodel.accessors.atomic;
 
+import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
 import edu.uci.ics.hyracks.data.std.api.AbstractPointable;
+import edu.uci.ics.hyracks.data.std.api.IComparable;
+import edu.uci.ics.hyracks.data.std.api.IHashable;
+import edu.uci.ics.hyracks.data.std.api.INumeric;
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointableFactory;
+import edu.uci.ics.hyracks.data.std.primitive.BytePointable;
+import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
+
+public class XSDecimalPointable extends AbstractPointable implements IHashable, IComparable, INumeric {
+    private final static int DECIMAL_PLACE_OFFSET = 0;
+    private final static int VALUE_OFFSET = 1;
+    private final static int PRECISION = 18;
+
+    public static final ITypeTraits TYPE_TRAITS = new ITypeTraits() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public boolean isFixedLength() {
+            return true;
+        }
+
+        @Override
+        public int getFixedLength() {
+            return 9;
+        }
+    };
+
+    public static final IPointableFactory FACTORY = new IPointableFactory() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public IPointable createPointable() {
+            return new XSDecimalPointable();
+        }
+
+        @Override
+        public ITypeTraits getTypeTraits() {
+            return TYPE_TRAITS;
+        }
+    };
+
+    @Override
+    public int compareTo(byte[] bytes, int start, int length) {
+        long v = getDecimalValue();
+        byte p = getDecimalPlace();
+        long ov = getDecimalValue(bytes, start);
+        byte op = getDecimalPlace(bytes, start);
+
+        // Make both long values have the decimal point at the same place. 
+        // TODO double check that precision is not being lost.
+        int diff = p - op;
+        if (diff > 0) {
+            v = Math.round(v / Math.pow(10, diff));
+        } else if (diff < 0) {
+            ov = Math.round(ov / Math.pow(10, diff));
+        }
 
-public class XSDecimalPointable extends AbstractPointable {
+        return v < ov ? -1 : (v > ov ? 1 : 0);
+    }
 
-    public double doubleValue() {
-        // TODO Auto-generated method stub
-        return 0;
+    @Override
+    public int compareTo(IPointable pointer) {
+        return compareTo(pointer.getByteArray(), pointer.getStartOffset(), pointer.getLength());
     }
 
-    public float floatValue() {
-        // TODO Auto-generated method stub
-        return 0;
+    public void setDecimal(long value, byte decimalPlace) {
+        BytePointable.setByte(bytes, start + DECIMAL_PLACE_OFFSET, decimalPlace);
+        LongPointable.setLong(bytes, start + VALUE_OFFSET, value);
+        normalize();
+    }
+
+    public void setDecimal(double doubleValue) {
+        setDecimal(doubleValue, bytes, start);
+    }
+    
+    public static void setDecimal(double doubleValue, byte[] bytes, int start) {
+        byte decimalPlace = 0;
+        long value = 0;
+        boolean pastDecimal = false;
+        int count = 0;
+        int c;
+        Double doubleObject = new Double(doubleValue);
+        String strTest = doubleObject.toString();
+        
+        for (int i = 0; i < strTest.length() && count < PRECISION; ++i) {
+            c = strTest.charAt(i);
+            if (Character.isDigit(c)) {
+                value = value * 10 + Character.getNumericValue(c);
+                if (pastDecimal) {
+                    decimalPlace++;
+                }
+                count++;
+            }
+            else {
+                pastDecimal = true;
+            }
+        }
+        
+        BytePointable.setByte(bytes, start + DECIMAL_PLACE_OFFSET, decimalPlace);
+        LongPointable.setLong(bytes, start + VALUE_OFFSET, value);
+        normalize(bytes, start);
+    }
+
+    public void normalize() {
+        normalize(bytes, start);
+    }
+
+    public static void normalize(byte[] bytes, int start) {
+        byte decimalPlace = getDecimalPlace(bytes, start);
+        long value = getDecimalValue(bytes, start);
+        // Normalize the value and take off trailing zeros.
+        while (value != 0 && value % 10 == 0) {
+            value -= 10;
+            --decimalPlace;
+        }
+        BytePointable.setByte(bytes, start + DECIMAL_PLACE_OFFSET, decimalPlace);
+        LongPointable.setLong(bytes, start + VALUE_OFFSET, value);
+    }
+
+    public byte getDecimalPlace() {
+        return BytePointable.getByte(bytes, start + DECIMAL_PLACE_OFFSET);
+    }
+
+    public static byte getDecimalPlace(byte[] bytes, int start) {
+        return BytePointable.getByte(bytes, start + DECIMAL_PLACE_OFFSET);
+    }
+
+    public long getDecimalValue() {
+        return LongPointable.getLong(bytes, start + VALUE_OFFSET);
+    }
+
+    public static long getDecimalValue(byte[] bytes, int start) {
+        return LongPointable.getLong(bytes, start + VALUE_OFFSET);
+    }
+
+    @Override
+    public int hash() {
+        long v = getDecimalValue();
+        return (int) (v ^ (v >>> 32));
+    }
+
+    public long getBeforeDecimalPlace() {
+        return Math.round(getDecimalValue() / Math.pow(10, getDecimalPlace()));
+    }
+
+    @Override
+    public byte byteValue() {
+        return (byte) getBeforeDecimalPlace();
+    }
+
+    @Override
+    public short shortValue() {
+        return (short) getBeforeDecimalPlace();
     }
 
+    @Override
+    public int intValue() {
+        return (int) getBeforeDecimalPlace();
+    }
+
+    @Override
     public long longValue() {
-        // TODO Auto-generated method stub
-        return 0;
+        return getBeforeDecimalPlace();
+    }
+
+    @Override
+    public float floatValue() {
+        return (float) (getDecimalValue() / Math.pow(10, getDecimalPlace()));
+    }
+
+    @Override
+    public double doubleValue() {
+        return getDecimalValue() / Math.pow(10, getDecimalPlace());
     }
 
 }
\ No newline at end of file

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDurationPointable.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDurationPointable.java?rev=1358704&r1=1358703&r2=1358704&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDurationPointable.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDurationPointable.java Sun Jul  8 08:37:08 2012
@@ -1,7 +1,72 @@
 package org.apache.vxquery.datamodel.accessors.atomic;
 
+import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
 import edu.uci.ics.hyracks.data.std.api.AbstractPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointableFactory;
+import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 
 public class XSDurationPointable extends AbstractPointable {
+    private final static int YEAR_MONTH_OFFSET = 0;
+    private final static int DAY_TIME_OFFSET = 4;
+    
+    public static final ITypeTraits TYPE_TRAITS = new ITypeTraits() {
+        private static final long serialVersionUID = 1L;
 
+        @Override
+        public boolean isFixedLength() {
+            return true;
+        }
+
+        @Override
+        public int getFixedLength() {
+            return 8;
+        }
+    };
+
+    public static final IPointableFactory FACTORY = new IPointableFactory() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public IPointable createPointable() {
+            return new XSDurationPointable();
+        }
+
+        @Override
+        public ITypeTraits getTypeTraits() {
+            return TYPE_TRAITS;
+        }
+    };
+
+    public static int getYearMonth(byte[] bytes, int start) {
+        return IntegerPointable.getInteger(bytes, start + YEAR_MONTH_OFFSET);
+    }
+
+    public int getYearMonth() {
+        return getYearMonth(bytes, start);
+    }
+
+    public static int getDayTime(byte[] bytes, int start) {
+        return IntegerPointable.getInteger(bytes, start + DAY_TIME_OFFSET);
+    }
+
+    public int getDayTime() {
+        return getDayTime(bytes, start);
+    }
+
+    public static void setYearMonth(byte[] bytes, int start, int value) {
+        IntegerPointable.setInteger(bytes, start + YEAR_MONTH_OFFSET, value);
+    }
+    
+    public void setYearMonth(int value) {
+        setYearMonth(bytes, start, value);
+    }
+    
+    public static void setDayTime(byte[] bytes, int start, int value) {
+        IntegerPointable.setInteger(bytes, start + DAY_TIME_OFFSET, value);
+    }
+
+    public void setDayTime(int value) {
+        setDayTime(bytes, start, value);
+    }
 }
\ No newline at end of file

Added: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSQNamePointable.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSQNamePointable.java?rev=1358704&view=auto
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSQNamePointable.java (added)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSQNamePointable.java Sun Jul  8 08:37:08 2012
@@ -0,0 +1,97 @@
+package org.apache.vxquery.datamodel.accessors.atomic;
+
+import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
+import edu.uci.ics.hyracks.data.std.api.AbstractPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointableFactory;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class XSQNamePointable extends AbstractPointable {
+    public static final ITypeTraits TYPE_TRAITS = new ITypeTraits() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public boolean isFixedLength() {
+            return false;
+        }
+
+        @Override
+        public int getFixedLength() {
+            return 0;
+        }
+    };
+
+    public static final IPointableFactory FACTORY = new IPointableFactory() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public IPointable createPointable() {
+            return new XSQNamePointable();
+        }
+
+        @Override
+        public ITypeTraits getTypeTraits() {
+            return TYPE_TRAITS;
+        }
+    };
+
+    /* TODO Do we need this?
+    public void setQName(IPointable uri, IPointable prefix, IPointable localName) {
+        int uriLength = uri.getLength();
+        int prefixLength = prefix.getLength();
+        set(uri);
+        set(prefix.getByteArray(), prefixLength, uriLength);
+        set(localName.getByteArray(), localName.getLength(), (uriLength + prefixLength));
+    }
+    */
+
+    public int getUriLength() {
+        return UTF8StringPointable.getUTFLength(bytes, start) + 2;
+    }
+
+    public static int getUriLength(byte[] bytes, int start) {
+        return UTF8StringPointable.getUTFLength(bytes, start) + 2;
+    }
+
+    public int getPrefixLength() {
+        return UTF8StringPointable.getUTFLength(bytes, start + getUriLength()) + 2;
+    }
+
+    public static int getPrefixLength(byte[] bytes, int start) {
+        return UTF8StringPointable.getUTFLength(bytes, start + getUriLength(bytes, start)) + 2;
+    }
+
+    public int getLocalNameLength() {
+        return UTF8StringPointable.getUTFLength(bytes, start + getUriLength() + getPrefixLength()) + 2;
+    }
+
+    public static int getLocalNameLength(byte[] bytes, int start) {
+        return UTF8StringPointable.getUTFLength(bytes,
+                start + getUriLength(bytes, start) + getPrefixLength(bytes, start)) + 2;
+    }
+
+    public void getUri(IPointable stringp) {
+        stringp.set(bytes, start, getUriLength());
+    }
+
+    public static void getUri(byte[] bytes, int start, IPointable stringp) {
+        stringp.set(bytes, start, getUriLength(bytes, start));
+    }
+
+    public void getPrefix(IPointable stringp) {
+        stringp.set(bytes, start + getUriLength(), getPrefixLength());
+    }
+
+    public static void getPrefix(byte[] bytes, int start, IPointable stringp) {
+        stringp.set(bytes, start + getUriLength(bytes, start), getPrefixLength(bytes, start));
+    }
+
+    public void getLocalName(IPointable stringp) {
+        stringp.set(bytes, start + getUriLength() + getPrefixLength(), getLocalNameLength());
+    }
+
+    public static void getLocalName(byte[] bytes, int start, IPointable stringp) {
+        stringp.set(bytes, start + getUriLength(bytes, start) + getPrefixLength(bytes, start),
+                getLocalNameLength(bytes, start));
+    }
+}