You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2012/08/07 01:44:32 UTC
svn commit: r1370065 - in
/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery:
datamodel/accessors/atomic/XSDecimalPointable.java
xmlquery/translator/XMLQueryTranslator.java
Author: prestonc
Date: Mon Aug 6 23:44:31 2012
New Revision: 1370065
URL: http://svn.apache.org/viewvc?rev=1370065&view=rev
Log:
Moved the double to decimal code to the cast function group.
Modified:
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java?rev=1370065&r1=1370064&r2=1370065&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java Mon Aug 6 23:44:31 2012
@@ -73,37 +73,6 @@ public class XSDecimalPointable extends
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);
}
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java?rev=1370065&r1=1370064&r2=1370065&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java Mon Aug 6 23:44:31 2012
@@ -23,7 +23,6 @@ import org.apache.vxquery.context.Static
import org.apache.vxquery.context.StaticContextImpl;
import org.apache.vxquery.context.ThinStaticContextImpl;
import org.apache.vxquery.context.XQueryVariable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
import org.apache.vxquery.datamodel.builders.atomic.StringValueBuilder;
import org.apache.vxquery.datamodel.values.ValueTag;
import org.apache.vxquery.exceptions.ErrorCode;
@@ -35,6 +34,7 @@ import org.apache.vxquery.functions.Func
import org.apache.vxquery.functions.Signature;
import org.apache.vxquery.functions.UserDefinedXQueryFunction;
import org.apache.vxquery.metadata.QueryResultDataSink;
+import org.apache.vxquery.runtime.functions.cast.CastToDecimalOperation;
import org.apache.vxquery.types.AnyItemType;
import org.apache.vxquery.types.AnyNodeType;
import org.apache.vxquery.types.AnyType;
@@ -160,6 +160,7 @@ import edu.uci.ics.hyracks.algebricks.co
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.plan.ALogicalPlanImpl;
+import edu.uci.ics.hyracks.data.std.primitive.DoublePointable;
import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
@@ -1875,10 +1876,12 @@ public class XMLQueryTranslator {
case BuiltinTypeConstants.XS_DECIMAL_TYPE_ID: {
baaos.reset();
try {
- dOut.write((byte) ValueTag.XS_DECIMAL_TAG);
- byte[] dBytes = new byte[XSDecimalPointable.TYPE_TRAITS.getFixedLength()];
- XSDecimalPointable.setDecimal(((Number) value).doubleValue(), dBytes, 0);
- dOut.write(dBytes);
+ // TODO Remove the creation of the separate byte array.
+ DoublePointable doublep = (DoublePointable) DoublePointable.FACTORY.createPointable();
+ doublep.set(new byte[DoublePointable.TYPE_TRAITS.getFixedLength()], 0, DoublePointable.TYPE_TRAITS.getFixedLength());
+ doublep.setDouble(((Number) value).doubleValue());
+ CastToDecimalOperation castToDecimal = new CastToDecimalOperation();
+ castToDecimal.convertDouble(doublep, dOut);
} catch (IOException e) {
throw new SystemException(ErrorCode.SYSE0001, e);
}