fix type promotion for numeric types
add error locations
clean up exception handling
diff --git a/asterix-app/data/type_promotion.adm b/asterix-app/data/type_promotion.adm
new file mode 100644
index 0000000..a3477c1
--- /dev/null
+++ b/asterix-app/data/type_promotion.adm
@@ -0,0 +1,93 @@
+{
+ "id": 1,
+ "int8": 100i8,
+ "int16": 100i8,
+ "int32": 100i8,
+ "int64": 100i8,
+ "float": 100i8,
+ "double": 100i8,
+ "int8_u": {{ 100i8 }},
+ "int8_o": [ 100i8 ],
+ "int16_u": {{ 100i8, 10000i16 }},
+ "int16_o": [ 100i8, 10000i16 ],
+ "int32_u": {{ 100i8, 10000i16, 1000000i32, 1000000 }},
+ "int32_o": [ 100i8, 10000i16, 1000000i32, 1000000 ],
+ "int64_u": {{ 100i8, 10000i16, 1000000i32, 1000000, 10000000000 }},
+ "int64_o": [ 100i8, 10000i16, 1000000i32, 1000000, 10000000000 ],
+ "float_u": {{ 100i8, 10000i16, 1000000i32, 1000000 }},
+ "float_o": [ 100i8, 10000i16, 1000000i32, 1000000 ],
+ "double_u": {{ 100i8, 10000i16, 1000000i32, 1000000, 10000000000 }},
+ "double_o": [ 100i8, 10000i16, 1000000i32, 1000000, 10000000000 ]
+}
+{
+ "id": 2,
+ "int8": 100i8,
+ "int16": 10000i16,
+ "int32": 10000i16,
+ "int64": 10000i16,
+ "float": 10000i16,
+ "double": 10000i16
+}
+{
+ "id": 3,
+ "int8": int8("100"),
+ "int16": int16("10000"),
+ "int32": int16("10000"),
+ "int64": int16("10000"),
+ "float": int16("10000"),
+ "double": int16("10000")
+}
+{
+ "id": 4,
+ "int8": 100i8,
+ "int16": 10000i16,
+ "int32": 1000000i32,
+ "int64": 1000000i32,
+ "float": 1000000i32,
+ "double": 1000000i32
+}
+{
+ "id": 5,
+ "int8": int8("100"),
+ "int16": int16("10000"),
+ "int32": int32("1000000"),
+ "int64": int32("1000000"),
+ "float": int32("1000000"),
+ "double": int32("1000000")
+}
+{
+ "id": 6,
+ "int8": 100i8,
+ "int16": 10000i16,
+ "int32": 1000000,
+ "int64": 1000000,
+ "float": 1000000,
+ "double": 1000000
+}
+{
+ "id": 7,
+ "int8": 100i8,
+ "int16": 10000i16,
+ "int32": 1000000i32,
+ "int64": 10000000000i64,
+ "float": 1000000i32,
+ "double": 10000000000i64
+}
+{
+ "id": 8,
+ "int8": int8("100"),
+ "int16": int16("10000"),
+ "int32": int32("1000000"),
+ "int64": int64("10000000000"),
+ "float": int32("1000000"),
+ "double": int64("10000000000")
+}
+{
+ "id": 9,
+ "int8": 100i8,
+ "int16": 10000i16,
+ "int32": 1000000,
+ "int64": 10000000000,
+ "float": 1000000,
+ "double": 10000000000
+}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/AsterixHyracksIntegrationUtil.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/AsterixHyracksIntegrationUtil.java
index 236df53..8e2a695 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/AsterixHyracksIntegrationUtil.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/AsterixHyracksIntegrationUtil.java
@@ -38,12 +38,12 @@
public static final int DEFAULT_HYRACKS_CC_CLIENT_PORT = 1098;
public static final int DEFAULT_HYRACKS_CC_CLUSTER_PORT = 1099;
-
+
private static ClusterControllerService cc;
private static NodeControllerService nc1;
private static NodeControllerService nc2;
private static IHyracksClientConnection hcc;
-
+
public static void init() throws Exception {
CCConfig ccConfig = new CCConfig();
ccConfig.clusterNetIpAddress = "127.0.0.1";
@@ -96,9 +96,9 @@
}
public static void deinit() throws Exception {
- nc2.stop();
- nc1.stop();
- cc.stop();
+ if (nc2 != null) nc2.stop();
+ if (nc1 != null) nc1.stop();
+ if (cc != null) cc.stop();
}
public static void runJob(JobSpecification spec) throws Exception {
@@ -107,5 +107,36 @@
GlobalConfig.ASTERIX_LOGGER.info(jobId.toString());
hcc.waitForCompletion(jobId);
}
+
+ /**
+ * main method to run a simple 2 node cluster in-process
+ *
+ * suggested VM arguments:
+ * <code>-enableassertions -Xmx2048m -Dfile.encoding=UTF-8</code>
+ *
+ * @param args unused
+ */
+ public static void main(String[] args) {
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ try {
+ deinit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ try {
+ System.setProperty(GlobalConfig.CONFIG_FILE_PROPERTY, "asterix-build-configuration.xml");
+ System.setProperty(GlobalConfig.WEB_SERVER_PORT_PROPERTY, "19002");
+
+ init();
+ while (true) {
+ Thread.sleep(10000);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java b/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java
index 18ed62a..e1b098b 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java
@@ -21,6 +21,8 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
@@ -35,6 +37,24 @@
import edu.uci.ics.hyracks.dataflow.common.comm.util.ByteBufferInputStream;
public class ResultUtils {
+ static Map<Character, String> HTML_ENTITIES = new HashMap<Character, String>();
+
+ static {
+ HTML_ENTITIES.put('"', """);
+ HTML_ENTITIES.put('&', "&");
+ HTML_ENTITIES.put('<', "<");
+ HTML_ENTITIES.put('>', ">");
+ }
+
+ public static String escapeHTML(String s) {
+ for (Character c : HTML_ENTITIES.keySet()) {
+ if (s.indexOf(c) >= 0) {
+ s = s.replace(c.toString(), HTML_ENTITIES.get(c));
+ }
+ }
+ return s;
+ }
+
public static void getJSONFromBuffer(ByteBuffer buffer, IFrameTupleAccessor fta, JSONArray resultRecords)
throws HyracksDataException {
ByteBufferInputStream bbis = new ByteBufferInputStream();
@@ -90,11 +110,11 @@
public static void webUIErrorHandler(PrintWriter out, Exception e) {
String errorTemplate = readTemplateFile("/webui/errortemplate.html", "%s\n%s\n%s");
- String errorOutput = String.format(errorTemplate, extractErrorMessage(e), extractErrorSummary(e),
- extractFullStackTrace(e));
+ String errorOutput = String.format(errorTemplate, escapeHTML(extractErrorMessage(e)),
+ escapeHTML(extractErrorSummary(e)), escapeHTML(extractFullStackTrace(e)));
out.println(errorOutput);
}
-
+
public static void webUIParseExceptionHandler(PrintWriter out, Throwable e, String query) {
String errorTemplate = readTemplateFile("/webui/errortemplate_message.html", "<pre class=\"error\">%s\n</pre>");
diff --git a/asterix-app/src/test/resources/runtimets/queries/load/type_promotion_0/type_promotion_0.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/load/type_promotion_0/type_promotion_0.1.ddl.aql
new file mode 100644
index 0000000..fb089b1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/load/type_promotion_0/type_promotion_0.1.ddl.aql
@@ -0,0 +1,28 @@
+drop dataverse TestDataverse if exists;
+create dataverse TestDataverse;
+use dataverse TestDataverse;
+
+create type TestType as {
+ id: int64,
+ int8: int8,
+ int16: int16,
+ int32: int32,
+ int64: int64,
+ float: float,
+ double: double,
+ int8_u: {{ int8 }}?,
+ int8_o: [ int8 ]?,
+ int16_u: {{ int16 }}?,
+ int16_o: [ int16 ]?,
+ int32_u: {{ int32 }}?,
+ int32_o: [ int32 ]?,
+ int64_u: {{ int64 }}?,
+ int64_o: [ int64 ]?,
+ float_u: {{ float }}?,
+ float_o: [ float ]?,
+ double_u: {{ double }}?,
+ double_o: [ double ]?
+}
+
+create dataset TestSet(TestType)
+primary key id;
diff --git a/asterix-app/src/test/resources/runtimets/queries/load/type_promotion_0/type_promotion_0.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/load/type_promotion_0/type_promotion_0.2.update.aql
new file mode 100644
index 0000000..55fc590
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/load/type_promotion_0/type_promotion_0.2.update.aql
@@ -0,0 +1,3 @@
+use dataverse TestDataverse;
+
+load dataset TestSet using localfs (("path"="nc1://data/type_promotion.adm"),("format"="adm"));
diff --git a/asterix-app/src/test/resources/runtimets/queries/load/type_promotion_0/type_promotion_0.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/load/type_promotion_0/type_promotion_0.3.query.aql
new file mode 100644
index 0000000..207c33d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/load/type_promotion_0/type_promotion_0.3.query.aql
@@ -0,0 +1,5 @@
+use dataverse TestDataverse;
+
+for $i in dataset TestSet
+order by $i.id
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/results/load/type_promotion_0/type_promotion_0.1.adm b/asterix-app/src/test/resources/runtimets/results/load/type_promotion_0/type_promotion_0.1.adm
new file mode 100644
index 0000000..10b0c92
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/load/type_promotion_0/type_promotion_0.1.adm
@@ -0,0 +1,9 @@
+{ "id": 1i64, "int8": 100i8, "int16": 100i16, "int32": 100, "int64": 100i64, "float": 100.0f, "double": 100.0d, "int8_u": {{ 100i8 }}, "int8_o": [ 100i8 ], "int16_u": {{ 100i16, 10000i16 }}, "int16_o": [ 100i16, 10000i16 ], "int32_u": {{ 100, 10000, 1000000, 1000000 }}, "int32_o": [ 100, 10000, 1000000, 1000000 ], "int64_u": {{ 100i64, 10000i64, 1000000i64, 1000000i64, 10000000000i64 }}, "int64_o": [ 100i64, 10000i64, 1000000i64, 1000000i64, 10000000000i64 ], "float_u": {{ 100.0f, 10000.0f, 1000000.0f, 1000000.0f }}, "float_o": [ 100.0f, 10000.0f, 1000000.0f, 1000000.0f ], "double_u": {{ 100.0d, 10000.0d, 1000000.0d, 1000000.0d, 1.0E10d }}, "double_o": [ 100.0d, 10000.0d, 1000000.0d, 1000000.0d, 1.0E10d ] }
+{ "id": 2i64, "int8": 100i8, "int16": 10000i16, "int32": 10000, "int64": 10000i64, "float": 10000.0f, "double": 10000.0d, "int8_u": null, "int8_o": null, "int16_u": null, "int16_o": null, "int32_u": null, "int32_o": null, "int64_u": null, "int64_o": null, "float_u": null, "float_o": null, "double_u": null, "double_o": null }
+{ "id": 3i64, "int8": 100i8, "int16": 10000i16, "int32": 10000, "int64": 10000i64, "float": 10000.0f, "double": 10000.0d, "int8_u": null, "int8_o": null, "int16_u": null, "int16_o": null, "int32_u": null, "int32_o": null, "int64_u": null, "int64_o": null, "float_u": null, "float_o": null, "double_u": null, "double_o": null }
+{ "id": 4i64, "int8": 100i8, "int16": 10000i16, "int32": 1000000, "int64": 1000000i64, "float": 1000000.0f, "double": 1000000.0d, "int8_u": null, "int8_o": null, "int16_u": null, "int16_o": null, "int32_u": null, "int32_o": null, "int64_u": null, "int64_o": null, "float_u": null, "float_o": null, "double_u": null, "double_o": null }
+{ "id": 5i64, "int8": 100i8, "int16": 10000i16, "int32": 1000000, "int64": 1000000i64, "float": 1000000.0f, "double": 1000000.0d, "int8_u": null, "int8_o": null, "int16_u": null, "int16_o": null, "int32_u": null, "int32_o": null, "int64_u": null, "int64_o": null, "float_u": null, "float_o": null, "double_u": null, "double_o": null }
+{ "id": 6i64, "int8": 100i8, "int16": 10000i16, "int32": 1000000, "int64": 1000000i64, "float": 1000000.0f, "double": 1000000.0d, "int8_u": null, "int8_o": null, "int16_u": null, "int16_o": null, "int32_u": null, "int32_o": null, "int64_u": null, "int64_o": null, "float_u": null, "float_o": null, "double_u": null, "double_o": null }
+{ "id": 7i64, "int8": 100i8, "int16": 10000i16, "int32": 1000000, "int64": 10000000000i64, "float": 1000000.0f, "double": 1.0E10d, "int8_u": null, "int8_o": null, "int16_u": null, "int16_o": null, "int32_u": null, "int32_o": null, "int64_u": null, "int64_o": null, "float_u": null, "float_o": null, "double_u": null, "double_o": null }
+{ "id": 8i64, "int8": 100i8, "int16": 10000i16, "int32": 1000000, "int64": 10000000000i64, "float": 1000000.0f, "double": 1.0E10d, "int8_u": null, "int8_o": null, "int16_u": null, "int16_o": null, "int32_u": null, "int32_o": null, "int64_u": null, "int64_o": null, "float_u": null, "float_o": null, "double_u": null, "double_o": null }
+{ "id": 9i64, "int8": 100i8, "int16": 10000i16, "int32": 1000000, "int64": 10000000000i64, "float": 1000000.0f, "double": 1.0E10d, "int8_u": null, "int8_o": null, "int16_u": null, "int16_o": null, "int32_u": null, "int32_o": null, "int64_u": null, "int64_o": null, "float_u": null, "float_o": null, "double_u": null, "double_o": null }
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index faab5aa..32608c4 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -4740,6 +4740,11 @@
<expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
</compilation-unit>
</test-case>
+ <test-case FilePath="load">
+ <compilation-unit name="type_promotion_0">
+ <output-dir compare="Text">type_promotion_0</output-dir>
+ </compilation-unit>
+ </test-case>
<test-case FilePath="user-defined-functions">
<compilation-unit name="query-issue244">
<output-dir compare="Text">query-issue244</output-dir>
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
index dae1fb1..4ce840d 100644
--- a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
@@ -96,6 +96,14 @@
new String(buffer, 0, bufpos);
}
+ public int getColumn() {
+ return column;
+ }
+
+ public int getLine() {
+ return line;
+ }
+
public static String tokenKindToString(int token) {
return tokenImage[token];
}
@@ -108,22 +116,14 @@
// Parse error management
// ================================================================================
- protected int parseError(String reason) throws [LEXER_NAME]Exception {
- StringBuilder message = new StringBuilder();
- message.append(reason).append("\n");
- message.append("Line: ").append(line).append("\n");
- message.append("Row: ").append(column).append("\n");
- throw new [LEXER_NAME]Exception(message.toString());
- }
-
protected int parseError(int ... tokens) throws [LEXER_NAME]Exception {
StringBuilder message = new StringBuilder();
- message.append("Error while parsing. ");
- message.append(" Line: ").append(line);
- message.append(" Row: ").append(column);
- message.append(" Expecting:");
- for (int tokenId : tokens){
- message.append(" ").append([LEXER_NAME].tokenKindToString(tokenId));
+ message.append("Parse error at (").append(line).append(", ").append(column).append(")");
+ if (tokens.length > 0) {
+ message.append(" expecting:");
+ for (int tokenId : tokens){
+ message.append(" ").append([LEXER_NAME].tokenKindToString(tokenId));
+ }
}
throw new [LEXER_NAME]Exception(message.toString());
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/cast/ACastVisitor.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/cast/ACastVisitor.java
index a711eb9..e93048e 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/cast/ACastVisitor.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/cast/ACastVisitor.java
@@ -112,7 +112,7 @@
try {
// do the promotion; note that the type tag field should be skipped
promoteComputer.promote(accessor.getByteArray(), accessor.getStartOffset() + 1,
- accessor.getLength() - 1, castBuffer);
+ accessor.getLength() - 1, castBuffer.getDataOutput());
arg.first.set(castBuffer);
} catch (IOException e) {
throw new AsterixException(e);
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/AbstractIntegerTypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/AbstractIntegerTypePromoteComputer.java
index 7df6f43..e10e41a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/AbstractIntegerTypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/AbstractIntegerTypePromoteComputer.java
@@ -14,23 +14,23 @@
*/
package edu.uci.ics.asterix.om.types.hierachy;
+import java.io.DataOutput;
import java.io.IOException;
import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
public abstract class AbstractIntegerTypePromoteComputer implements ITypePromoteComputer {
- public void promoteIntegerType(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue,
+ public void promoteIntegerType(byte[] data, int start, int length, DataOutput out,
ATypeTag targetType, int targetTypeLength) throws IOException {
- storageForPromotedValue.getDataOutput().writeByte(targetType.serialize());
+ out.writeByte(targetType.serialize());
long num = 0;
for (int i = start; i < start + length; i++) {
num += (data[i] & 0xff) << ((length - 1 - (i - start)) * 8);
}
for (int i = targetTypeLength - 1; i >= 0; i--) {
- storageForPromotedValue.getDataOutput().writeByte((byte) ((num >>> (i * 8)) & 0xFF));
+ out.writeByte((byte) ((num >>> (i * 8)) & 0xFF));
}
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/FloatToDoubleTypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/FloatToDoubleTypePromoteComputer.java
index a3cfbc8..70c6097 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/FloatToDoubleTypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/FloatToDoubleTypePromoteComputer.java
@@ -14,10 +14,10 @@
*/
package edu.uci.ics.asterix.om.types.hierachy;
+import java.io.DataOutput;
import java.io.IOException;
import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
import edu.uci.ics.hyracks.dataflow.common.data.marshalling.DoubleSerializerDeserializer;
import edu.uci.ics.hyracks.dataflow.common.data.marshalling.FloatSerializerDeserializer;
@@ -33,11 +33,11 @@
* @see edu.uci.ics.asterix.om.types.hierachy.ITypePromoteComputer#promote(byte[], int, int, edu.uci.ics.hyracks.data.std.api.IMutableValueStorage)
*/
@Override
- public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+ public void promote(byte[] data, int start, int length, DataOutput out)
throws IOException {
- storageForPromotedValue.getDataOutput().writeByte(ATypeTag.DOUBLE.serialize());
+ out.writeByte(ATypeTag.DOUBLE.serialize());
DoubleSerializerDeserializer.INSTANCE.serialize((double) (FloatSerializerDeserializer.getFloat(data, start)),
- storageForPromotedValue.getDataOutput());
+ out);
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/ITypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/ITypePromoteComputer.java
index e8612af..995b61a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/ITypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/ITypePromoteComputer.java
@@ -14,12 +14,11 @@
*/
package edu.uci.ics.asterix.om.types.hierachy;
+import java.io.DataOutput;
import java.io.IOException;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
-
public interface ITypePromoteComputer {
- void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue) throws IOException;
+ void promote(byte[] data, int start, int length, DataOutput out) throws IOException;
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToDoubleTypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToDoubleTypePromoteComputer.java
index dfd116e..4987b94 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToDoubleTypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToDoubleTypePromoteComputer.java
@@ -14,10 +14,10 @@
*/
package edu.uci.ics.asterix.om.types.hierachy;
+import java.io.DataOutput;
import java.io.IOException;
import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
import edu.uci.ics.hyracks.dataflow.common.data.marshalling.DoubleSerializerDeserializer;
public class IntegerToDoubleTypePromoteComputer implements ITypePromoteComputer {
@@ -29,14 +29,14 @@
}
@Override
- public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+ public void promote(byte[] data, int start, int length, DataOutput out)
throws IOException {
- storageForPromotedValue.getDataOutput().writeByte(ATypeTag.DOUBLE.serialize());
+ out.writeByte(ATypeTag.DOUBLE.serialize());
long val = 0L;
for (int i = 0; i < length; i++) {
val += ((long) (data[start + i] & 0xff)) << (8 * (length - 1 - i));
}
- DoubleSerializerDeserializer.INSTANCE.serialize(Double.valueOf(val), storageForPromotedValue.getDataOutput());
+ DoubleSerializerDeserializer.INSTANCE.serialize(Double.valueOf(val), out);
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToFloatTypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToFloatTypePromoteComputer.java
index c1bd9e5..db8d59a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToFloatTypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToFloatTypePromoteComputer.java
@@ -14,10 +14,10 @@
*/
package edu.uci.ics.asterix.om.types.hierachy;
+import java.io.DataOutput;
import java.io.IOException;
import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
import edu.uci.ics.hyracks.dataflow.common.data.marshalling.FloatSerializerDeserializer;
public class IntegerToFloatTypePromoteComputer implements ITypePromoteComputer {
@@ -32,14 +32,14 @@
* @see edu.uci.ics.asterix.om.types.hierachy.ITypePromoteComputer#promote(byte[], int, int, edu.uci.ics.hyracks.data.std.api.IMutableValueStorage)
*/
@Override
- public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+ public void promote(byte[] data, int start, int length, DataOutput out)
throws IOException {
- storageForPromotedValue.getDataOutput().writeByte(ATypeTag.FLOAT.serialize());
+ out.writeByte(ATypeTag.FLOAT.serialize());
float val = 0;
for (int i = 0; i < length; i++) {
val += (data[start + i] & 0xff) << (8 * (length - 1 - i));
}
- FloatSerializerDeserializer.INSTANCE.serialize(val, storageForPromotedValue.getDataOutput());
+ FloatSerializerDeserializer.INSTANCE.serialize(val, out);
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt16TypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt16TypePromoteComputer.java
index 8835a57..6731c8c 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt16TypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt16TypePromoteComputer.java
@@ -14,10 +14,10 @@
*/
package edu.uci.ics.asterix.om.types.hierachy;
+import java.io.DataOutput;
import java.io.IOException;
import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
public class IntegerToInt16TypePromoteComputer extends AbstractIntegerTypePromoteComputer {
@@ -31,9 +31,9 @@
* @see edu.uci.ics.asterix.om.types.hierachy.ITypePromoteComputer#promote(byte[], int, int, edu.uci.ics.hyracks.data.std.api.IMutableValueStorage)
*/
@Override
- public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+ public void promote(byte[] data, int start, int length, DataOutput out)
throws IOException {
- promoteIntegerType(data, start, length, storageForPromotedValue, ATypeTag.INT16, 2);
+ promoteIntegerType(data, start, length, out, ATypeTag.INT16, 2);
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt32TypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt32TypePromoteComputer.java
index 8a808bf..6e3978c 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt32TypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt32TypePromoteComputer.java
@@ -14,10 +14,10 @@
*/
package edu.uci.ics.asterix.om.types.hierachy;
+import java.io.DataOutput;
import java.io.IOException;
import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
public class IntegerToInt32TypePromoteComputer extends AbstractIntegerTypePromoteComputer {
@@ -27,9 +27,9 @@
}
@Override
- public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+ public void promote(byte[] data, int start, int length, DataOutput out)
throws IOException {
- promoteIntegerType(data, start, length, storageForPromotedValue, ATypeTag.INT32, 4);
+ promoteIntegerType(data, start, length, out, ATypeTag.INT32, 4);
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt64TypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt64TypePromoteComputer.java
index b24604d..448dd8e 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt64TypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt64TypePromoteComputer.java
@@ -14,10 +14,10 @@
*/
package edu.uci.ics.asterix.om.types.hierachy;
+import java.io.DataOutput;
import java.io.IOException;
import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
public class IntegerToInt64TypePromoteComputer extends AbstractIntegerTypePromoteComputer {
@@ -30,9 +30,9 @@
* @see edu.uci.ics.asterix.om.types.hierachy.ITypePromoteComputer#promote(byte[], int, int, edu.uci.ics.hyracks.data.std.api.IMutableValueStorage)
*/
@Override
- public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+ public void promote(byte[] data, int start, int length, DataOutput out)
throws IOException {
- promoteIntegerType(data, start, length, storageForPromotedValue, ATypeTag.INT64, 8);
+ promoteIntegerType(data, start, length, out, ATypeTag.INT64, 8);
}
}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractMinMaxAggregateFunction.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractMinMaxAggregateFunction.java
index 29aba33..b961ef1 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractMinMaxAggregateFunction.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractMinMaxAggregateFunction.java
@@ -101,7 +101,7 @@
tempValForCasting.reset();
try {
tpc.promote(outputVal.getByteArray(), outputVal.getStartOffset() + 1,
- outputVal.getLength() - 1, tempValForCasting);
+ outputVal.getLength() - 1, tempValForCasting.getDataOutput());
} catch (IOException e) {
throw new AlgebricksException(e);
}
@@ -119,7 +119,7 @@
tempValForCasting.reset();
try {
tpc.promote(inputVal.getByteArray(), inputVal.getStartOffset() + 1, inputVal.getLength() - 1,
- tempValForCasting);
+ tempValForCasting.getDataOutput());
} catch (IOException e) {
throw new AlgebricksException(e);
}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
index 2dd1bc6..735bf2a5 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
@@ -50,6 +50,7 @@
import edu.uci.ics.asterix.om.types.AUnorderedListType;
import edu.uci.ics.asterix.om.types.IAType;
import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
+import edu.uci.ics.asterix.om.types.hierachy.ITypePromoteComputer;
import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
import edu.uci.ics.asterix.runtime.operators.file.adm.AdmLexer;
import edu.uci.ics.asterix.runtime.operators.file.adm.AdmLexerException;
@@ -66,6 +67,7 @@
protected boolean datasetRec;
private int nullableFieldId = 0;
+ private ArrayBackedValueStorage castBuffer = new ArrayBackedValueStorage();
private Queue<ArrayBackedValueStorage> baaosPool = new ArrayDeque<ArrayBackedValueStorage>();
private Queue<IARecordBuilder> recordBuilderPool = new ArrayDeque<IARecordBuilder>();
@@ -73,13 +75,59 @@
private Queue<IAsterixListBuilder> unorderedListBuilderPool = new ArrayDeque<IAsterixListBuilder>();
private String mismatchErrorMessage = "Mismatch Type, expecting a value of type ";
+ private String mismatchErrorMessage2 = " got a value of type ";
+ static class ParseException extends AsterixException {
+ private static final long serialVersionUID = 1L;
+ private int line = -1;
+ private int column = -1;
+
+ public ParseException(String message) {
+ super(message);
+ }
+
+ public ParseException(Throwable cause) {
+ super(cause);
+ }
+
+ public ParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ParseException(Throwable cause, int line, int column) {
+ super(cause);
+ setLocation(line, column);
+ }
+
+ public void setLocation(int line, int column) {
+ this.line = line;
+ this.column = column;
+ }
+
+ public String getMessage() {
+ StringBuilder msg = new StringBuilder("Parse error");
+ if (line >= 0) {
+ if (column >= 0) {
+ msg.append(" at (" + line + ", " + column + ")");
+ } else {
+ msg.append(" in line " + line);
+ }
+ }
+ return msg.append(": " + super.getMessage()).toString();
+ }
+ }
+
@Override
- public boolean parse(DataOutput out) throws HyracksDataException {
+ public boolean parse(DataOutput out) throws AsterixException {
try {
return parseAdmInstance((IAType) recordType, datasetRec, out);
- } catch (Exception e) {
- throw new HyracksDataException(e);
+ } catch (IOException e) {
+ throw new ParseException(e, admLexer.getLine(), admLexer.getColumn());
+ } catch (AdmLexerException e) {
+ throw new AsterixException(e);
+ } catch (ParseException e) {
+ e.setLocation(admLexer.getLine(), admLexer.getColumn());
+ throw e;
}
}
@@ -90,18 +138,13 @@
try {
admLexer = new AdmLexer(new java.io.InputStreamReader(in));
} catch (IOException e) {
- throw new AsterixException(e);
+ throw new ParseException(e);
}
}
protected boolean parseAdmInstance(IAType objectType, boolean datasetRec, DataOutput out) throws AsterixException,
- IOException {
- int token;
- try {
- token = admLexer.next();
- } catch (AdmLexerException e) {
- throw new AsterixException(e);
- }
+ IOException, AdmLexerException {
+ int token = admLexer.next();
if (token == AdmLexer.TOKEN_EOF) {
return false;
} else {
@@ -111,21 +154,21 @@
}
private void admFromLexerStream(int token, IAType objectType, DataOutput out, Boolean datasetRec)
- throws AsterixException, IOException {
+ throws AsterixException, IOException, AdmLexerException {
switch (token) {
case AdmLexer.TOKEN_NULL_LITERAL: {
if (checkType(ATypeTag.NULL, objectType, out)) {
nullSerde.serialize(ANull.NULL, out);
} else
- throw new AsterixException(" This field can not be null ");
+ throw new ParseException("This field can not be null");
break;
}
case AdmLexer.TOKEN_TRUE_LITERAL: {
if (checkType(ATypeTag.BOOLEAN, objectType, out)) {
booleanSerde.serialize(ABoolean.TRUE, out);
} else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
+ throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
break;
}
case AdmLexer.TOKEN_BOOLEAN_CONS: {
@@ -136,15 +179,11 @@
if (checkType(ATypeTag.BOOLEAN, objectType, out)) {
booleanSerde.serialize(ABoolean.FALSE, out);
} else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
+ throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
break;
}
case AdmLexer.TOKEN_DOUBLE_LITERAL: {
- if (checkType(ATypeTag.DOUBLE, objectType, out)) {
- aDouble.setValue(Double.parseDouble(admLexer.getLastTokenImage()));
- doubleSerde.serialize(aDouble, out);
- } else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
+ parseToNumericTarget(ATypeTag.DOUBLE, objectType, out);
break;
}
case AdmLexer.TOKEN_DOUBLE_CONS: {
@@ -152,11 +191,7 @@
break;
}
case AdmLexer.TOKEN_FLOAT_LITERAL: {
- if (checkType(ATypeTag.FLOAT, objectType, out)) {
- aFloat.setValue(Float.parseFloat(admLexer.getLastTokenImage()));
- floatSerde.serialize(aFloat, out);
- } else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
+ parseToNumericTarget(ATypeTag.FLOAT, objectType, out);
break;
}
case AdmLexer.TOKEN_FLOAT_CONS: {
@@ -164,10 +199,7 @@
break;
}
case AdmLexer.TOKEN_INT8_LITERAL: {
- if (checkType(ATypeTag.INT8, objectType, out)) {
- parseInt8(admLexer.getLastTokenImage(), out);
- } else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
+ parseAndCastNumeric(ATypeTag.INT8, objectType, out);
break;
}
case AdmLexer.TOKEN_INT8_CONS: {
@@ -175,22 +207,19 @@
break;
}
case AdmLexer.TOKEN_INT16_LITERAL: {
- if (checkType(ATypeTag.INT16, objectType, out)) {
- parseInt16(admLexer.getLastTokenImage(), out);
- } else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
+ parseAndCastNumeric(ATypeTag.INT16, objectType, out);
break;
}
case AdmLexer.TOKEN_INT16_CONS: {
parseConstructor(ATypeTag.INT16, objectType, out);
break;
}
- case AdmLexer.TOKEN_INT_LITERAL:
+ case AdmLexer.TOKEN_INT_LITERAL: {
+ parseToNumericTarget(ATypeTag.INT32, objectType, out);
+ break;
+ }
case AdmLexer.TOKEN_INT32_LITERAL: {
- if (checkType(ATypeTag.INT32, objectType, out)) {
- parseInt32(admLexer.getLastTokenImage(), out);
- } else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
+ parseAndCastNumeric(ATypeTag.INT32, objectType, out);
break;
}
case AdmLexer.TOKEN_INT32_CONS: {
@@ -198,10 +227,7 @@
break;
}
case AdmLexer.TOKEN_INT64_LITERAL: {
- if (checkType(ATypeTag.INT64, objectType, out)) {
- parseInt64(admLexer.getLastTokenImage(), out);
- } else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
+ parseAndCastNumeric(ATypeTag.INT64, objectType, out);
break;
}
case AdmLexer.TOKEN_INT64_CONS: {
@@ -214,7 +240,7 @@
admLexer.getLastTokenImage().length() - 1));
stringSerde.serialize(aString, out);
} else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
+ throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
break;
}
case AdmLexer.TOKEN_STRING_CONS: {
@@ -234,58 +260,46 @@
break;
}
case AdmLexer.TOKEN_INTERVAL_DATE_CONS: {
- try {
- if (checkType(ATypeTag.INTERVAL, objectType, out)) {
- if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
- if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
- AIntervalSerializerDeserializer.parseDate(admLexer.getLastTokenImage(), out);
+ if (checkType(ATypeTag.INTERVAL, objectType, out)) {
+ if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
+ if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
+ AIntervalSerializerDeserializer.parseDate(admLexer.getLastTokenImage(), out);
- if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
- break;
- }
+ if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
+ break;
}
}
}
- } catch (AdmLexerException ex) {
- throw new AsterixException(ex);
}
- throw new AsterixException("Wrong interval data parsing for date interval.");
+ throw new ParseException("Wrong interval data parsing for date interval.");
}
case AdmLexer.TOKEN_INTERVAL_TIME_CONS: {
- try {
- if (checkType(ATypeTag.INTERVAL, objectType, out)) {
- if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
- if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
- AIntervalSerializerDeserializer.parseTime(admLexer.getLastTokenImage(), out);
+ if (checkType(ATypeTag.INTERVAL, objectType, out)) {
+ if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
+ if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
+ AIntervalSerializerDeserializer.parseTime(admLexer.getLastTokenImage(), out);
- if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
- break;
- }
+ if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
+ break;
}
}
}
- } catch (AdmLexerException ex) {
- throw new AsterixException(ex);
}
- throw new AsterixException("Wrong interval data parsing for time interval.");
+ throw new ParseException("Wrong interval data parsing for time interval.");
}
case AdmLexer.TOKEN_INTERVAL_DATETIME_CONS: {
- try {
- if (checkType(ATypeTag.INTERVAL, objectType, out)) {
- if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
- if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
- AIntervalSerializerDeserializer.parseDatetime(admLexer.getLastTokenImage(), out);
+ if (checkType(ATypeTag.INTERVAL, objectType, out)) {
+ if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
+ if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
+ AIntervalSerializerDeserializer.parseDatetime(admLexer.getLastTokenImage(), out);
- if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
- break;
- }
+ if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
+ break;
}
}
}
- } catch (AdmLexerException ex) {
- throw new AsterixException(ex);
}
- throw new AsterixException("Wrong interval data parsing for datetime interval.");
+ throw new ParseException("Wrong interval data parsing for datetime interval.");
}
case AdmLexer.TOKEN_DURATION_CONS: {
parseConstructor(ATypeTag.DURATION, objectType, out);
@@ -328,7 +342,7 @@
objectType = getComplexType(objectType, ATypeTag.UNORDEREDLIST);
parseUnorderedList((AUnorderedListType) objectType, out);
} else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeTag());
+ throw new ParseException(mismatchErrorMessage + objectType.getTypeTag());
break;
}
@@ -337,7 +351,7 @@
objectType = getComplexType(objectType, ATypeTag.ORDEREDLIST);
parseOrderedList((AOrderedListType) objectType, out);
} else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeTag());
+ throw new ParseException(mismatchErrorMessage + objectType.getTypeTag());
break;
}
case AdmLexer.TOKEN_START_RECORD: {
@@ -345,53 +359,19 @@
objectType = getComplexType(objectType, ATypeTag.RECORD);
parseRecord((ARecordType) objectType, out, datasetRec);
} else
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeTag());
+ throw new ParseException(mismatchErrorMessage + objectType.getTypeTag());
break;
}
case AdmLexer.TOKEN_EOF: {
break;
}
default: {
- throw new AsterixException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token) + ".");
+ throw new ParseException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token) + ".");
}
}
}
- private void parseDatetime(String datetime, DataOutput out) throws AsterixException, IOException {
- try {
- ADateTimeSerializerDeserializer.parse(datetime, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
- }
- }
-
- private void parseDuration(String duration, DataOutput out) throws AsterixException {
- try {
- ADurationSerializerDeserializer.parse(duration, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
- }
-
- }
-
- private void parseYearMonthDuration(String duration, DataOutput out) throws AsterixException {
- try {
- AYearMonthDurationSerializerDeserializer.INSTANCE.parse(duration, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
- }
- }
-
- private void parseDayTimeDuration(String duration, DataOutput out) throws AsterixException {
- try {
- ADayTimeDurationSerializerDeserializer.INSTANCE.parse(duration, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
- }
- }
-
private IAType getComplexType(IAType aObjectType, ATypeTag tag) {
-
if (aObjectType == null) {
return null;
}
@@ -400,7 +380,7 @@
return aObjectType;
if (aObjectType.getTypeTag() == ATypeTag.UNION) {
- unionList = ((AUnionType) aObjectType).getUnionList();
+ List<IAType> unionList = ((AUnionType) aObjectType).getUnionList();
for (int i = 0; i < unionList.size(); i++)
if (unionList.get(i).getTypeTag() == tag) {
return unionList.get(i);
@@ -409,34 +389,36 @@
return null; // wont get here
}
- List<IAType> unionList;
-
- private boolean checkType(ATypeTag expectedTypeTag, IAType aObjectType, DataOutput out) throws IOException {
-
- if (aObjectType == null)
- return true;
-
+ private ATypeTag getTargetTypeTag(ATypeTag expectedTypeTag, IAType aObjectType) throws IOException {
+ if (aObjectType == null) {
+ return expectedTypeTag;
+ }
if (aObjectType.getTypeTag() != ATypeTag.UNION) {
- return ATypeHierarchy.canPromote(expectedTypeTag, aObjectType.getTypeTag());
+ final ATypeTag typeTag = aObjectType.getTypeTag();
+ return ATypeHierarchy.canPromote(expectedTypeTag, typeTag) ? typeTag : null;
} else { // union
- unionList = ((AUnionType) aObjectType).getUnionList();
+ List<IAType> unionList = ((AUnionType) aObjectType).getUnionList();
for (IAType t : unionList) {
- if (ATypeHierarchy.canPromote(t.getTypeTag(), expectedTypeTag)) {
- return true;
+ final ATypeTag typeTag = t.getTypeTag();
+ if (ATypeHierarchy.canPromote(expectedTypeTag, typeTag)) {
+ return typeTag;
}
}
}
- return false;
+ return null;
+ }
+
+ private boolean checkType(ATypeTag expectedTypeTag, IAType aObjectType, DataOutput out) throws IOException {
+ return getTargetTypeTag(expectedTypeTag, aObjectType) != null;
}
private void parseRecord(ARecordType recType, DataOutput out, Boolean datasetRec) throws IOException,
- AsterixException {
+ AsterixException, AdmLexerException {
ArrayBackedValueStorage fieldValueBuffer = getTempBuffer();
ArrayBackedValueStorage fieldNameBuffer = getTempBuffer();
IARecordBuilder recBuilder = getRecordBuilder();
- // Boolean[] nulls = null;
BitSet nulls = null;
if (datasetRec) {
if (recType != null) {
@@ -460,11 +442,11 @@
int fieldId = 0;
IAType fieldType = null;
do {
- token = nextToken();
+ token = admLexer.next();
switch (token) {
case AdmLexer.TOKEN_END_RECORD: {
if (expectingRecordField) {
- throw new AsterixException("Found END_RECORD while expecting a record field.");
+ throw new ParseException("Found END_RECORD while expecting a record field.");
}
inRecord = false;
break;
@@ -481,7 +463,7 @@
admLexer.getLastTokenImage().length() - 1);
fieldId = recBuilder.getFieldId(fldName);
if (fieldId < 0 && !recType.isOpen()) {
- throw new AsterixException("This record is closed, you can not add extra fields !!");
+ throw new ParseException("This record is closed, you can not add extra fields !!");
} else if (fieldId < 0 && recType.isOpen()) {
aStringFieldName.setValue(admLexer.getLastTokenImage().substring(1,
admLexer.getLastTokenImage().length() - 1));
@@ -502,13 +484,13 @@
fieldType = null;
}
- token = nextToken();
+ token = admLexer.next();
if (token != AdmLexer.TOKEN_COLON) {
- throw new AsterixException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token)
+ throw new ParseException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token)
+ " while expecting \":\".");
}
- token = nextToken();
+ token = admLexer.next();
this.admFromLexerStream(token, fieldType, fieldValueBuffer.getDataOutput(), false);
if (openRecordField) {
if (fieldValueBuffer.getByteArray()[0] != ATypeTag.NULL.serialize())
@@ -527,16 +509,16 @@
}
case AdmLexer.TOKEN_COMMA: {
if (first) {
- throw new AsterixException("Found COMMA before any record field.");
+ throw new ParseException("Found COMMA before any record field.");
}
if (expectingRecordField) {
- throw new AsterixException("Found COMMA while expecting a record field.");
+ throw new ParseException("Found COMMA while expecting a record field.");
}
expectingRecordField = true;
break;
}
default: {
- throw new AsterixException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token)
+ throw new ParseException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token)
+ " while parsing record fields.");
}
}
@@ -546,7 +528,7 @@
if (recType != null) {
nullableFieldId = checkNullConstraints(recType, nulls);
if (nullableFieldId != -1)
- throw new AsterixException("Field " + nullableFieldId + " can not be null");
+ throw new ParseException("Field " + nullableFieldId + " can not be null");
}
recBuilder.write(out, true);
returnRecordBuilder(recBuilder);
@@ -555,7 +537,6 @@
}
private int checkNullConstraints(ARecordType recType, BitSet nulls) {
-
boolean isNull = false;
for (int i = 0; i < recType.getFieldTypes().length; i++)
if (nulls.get(i) == false) {
@@ -564,7 +545,7 @@
return i;
if (type.getTypeTag() == ATypeTag.UNION) { // union
- unionList = ((AUnionType) type).getUnionList();
+ List<IAType> unionList = ((AUnionType) type).getUnionList();
for (int j = 0; j < unionList.size(); j++)
if (unionList.get(j).getTypeTag() == ATypeTag.NULL) {
isNull = true;
@@ -577,8 +558,8 @@
return -1;
}
- private void parseOrderedList(AOrderedListType oltype, DataOutput out) throws IOException, AsterixException {
-
+ private void parseOrderedList(AOrderedListType oltype, DataOutput out) throws IOException, AsterixException,
+ AdmLexerException {
ArrayBackedValueStorage itemBuffer = getTempBuffer();
OrderedListBuilder orderedListBuilder = (OrderedListBuilder) getOrderedListBuilder();
@@ -592,18 +573,18 @@
boolean expectingListItem = false;
boolean first = true;
do {
- token = nextToken();
+ token = admLexer.next();
if (token == AdmLexer.TOKEN_END_ORDERED_LIST) {
if (expectingListItem) {
- throw new AsterixException("Found END_COLLECTION while expecting a list item.");
+ throw new ParseException("Found END_COLLECTION while expecting a list item.");
}
inList = false;
} else if (token == AdmLexer.TOKEN_COMMA) {
if (first) {
- throw new AsterixException("Found COMMA before any list item.");
+ throw new ParseException("Found COMMA before any list item.");
}
if (expectingListItem) {
- throw new AsterixException("Found COMMA while expecting a list item.");
+ throw new ParseException("Found COMMA while expecting a list item.");
}
expectingListItem = true;
} else {
@@ -620,8 +601,8 @@
returnTempBuffer(itemBuffer);
}
- private void parseUnorderedList(AUnorderedListType uoltype, DataOutput out) throws IOException, AsterixException {
-
+ private void parseUnorderedList(AUnorderedListType uoltype, DataOutput out) throws IOException, AsterixException,
+ AdmLexerException {
ArrayBackedValueStorage itemBuffer = getTempBuffer();
UnorderedListBuilder unorderedListBuilder = (UnorderedListBuilder) getUnorderedListBuilder();
@@ -636,23 +617,23 @@
boolean expectingListItem = false;
boolean first = true;
do {
- token = nextToken();
+ token = admLexer.next();
if (token == AdmLexer.TOKEN_END_RECORD) {
- if (nextToken() == AdmLexer.TOKEN_END_RECORD) {
+ if (admLexer.next() == AdmLexer.TOKEN_END_RECORD) {
if (expectingListItem) {
- throw new AsterixException("Found END_COLLECTION while expecting a list item.");
+ throw new ParseException("Found END_COLLECTION while expecting a list item.");
} else {
inList = false;
}
} else {
- throw new AsterixException("Found END_RECORD while expecting a list item.");
+ throw new ParseException("Found END_RECORD while expecting a list item.");
}
} else if (token == AdmLexer.TOKEN_COMMA) {
if (first) {
- throw new AsterixException("Found COMMA before any list item.");
+ throw new ParseException("Found COMMA before any list item.");
}
if (expectingListItem) {
- throw new AsterixException("Found COMMA while expecting a list item.");
+ throw new ParseException("Found COMMA while expecting a list item.");
}
expectingListItem = true;
} else {
@@ -668,16 +649,6 @@
returnTempBuffer(itemBuffer);
}
- private int nextToken() throws AsterixException {
- try {
- return admLexer.next();
- } catch (AdmLexerException e) {
- throw new AsterixException(e);
- } catch (IOException e) {
- throw new AsterixException(e);
- }
- }
-
private IARecordBuilder getRecordBuilder() {
RecordBuilder recBuilder = (RecordBuilder) recordBuilderPool.poll();
if (recBuilder != null)
@@ -727,341 +698,272 @@
baaosPool.add(tempBaaos);
}
- private void parseConstructor(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException {
- try {
+ private void parseToNumericTarget(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException,
+ IOException {
+ final ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType);
+ if (targetTypeTag == null || !parseValue(admLexer.getLastTokenImage(), targetTypeTag, out)) {
+ throw new ParseException(mismatchErrorMessage + objectType.getTypeName() + mismatchErrorMessage2
+ + typeTag);
+ }
+ }
+
+ private void parseAndCastNumeric(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException,
+ IOException {
+ final ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType);
+ DataOutput dataOutput = out;
+ if (targetTypeTag != typeTag) {
+ castBuffer.reset();
+ dataOutput = castBuffer.getDataOutput();
+ }
+
+ if (targetTypeTag == null || !parseValue(admLexer.getLastTokenImage(), typeTag, dataOutput)) {
+ throw new ParseException(mismatchErrorMessage + objectType.getTypeName() + mismatchErrorMessage2
+ + typeTag);
+ }
+
+ if (targetTypeTag != typeTag) {
+ ITypePromoteComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag, targetTypeTag);
+ // the availability if the promote computer should be consistent with the availability of a target type
+ assert promoteComputer != null;
+ // do the promotion; note that the type tag field should be skipped
+ promoteComputer.promote(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1,
+ castBuffer.getLength() - 1, out);
+ }
+ }
+
+ private void parseConstructor(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException,
+ AdmLexerException, IOException {
+ final ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType);
+ if (targetTypeTag != null) {
+ DataOutput dataOutput = out;
+ if (targetTypeTag != typeTag) {
+ castBuffer.reset();
+ dataOutput = castBuffer.getDataOutput();
+ }
int token = admLexer.next();
if (token == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
- if (checkType(typeTag, objectType, out)) {
+ token = admLexer.next();
+ if (token == AdmLexer.TOKEN_STRING_LITERAL) {
+ final String unquoted = admLexer.getLastTokenImage().substring(1,
+ admLexer.getLastTokenImage().length() - 1);
+ if (!parseValue(unquoted, typeTag, dataOutput)) {
+ throw new ParseException("Missing deserializer method for constructor: "
+ + AdmLexer.tokenKindToString(token) + ".");
+ }
token = admLexer.next();
- if (token == AdmLexer.TOKEN_STRING_LITERAL) {
- switch (typeTag) {
- case BOOLEAN:
- parseBoolean(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case INT8:
- parseInt8(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case INT16:
- parseInt16(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case INT32:
- parseInt32(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case INT64:
- parseInt64(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case FLOAT:
- aFloat.setValue(Float.parseFloat(admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1)));
- floatSerde.serialize(aFloat, out);
- break;
- case DOUBLE:
- aDouble.setValue(Double.parseDouble(admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1)));
- doubleSerde.serialize(aDouble, out);
- break;
- case STRING:
- aString.setValue(admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1));
- stringSerde.serialize(aString, out);
- break;
- case TIME:
- parseTime(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case DATE:
- parseDate(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case DATETIME:
- parseDatetime(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case DURATION:
- parseDuration(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case DAYTIMEDURATION:
- parseDayTimeDuration(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case YEARMONTHDURATION:
- parseYearMonthDuration(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case POINT:
- parsePoint(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case POINT3D:
- parsePoint3d(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case CIRCLE:
- parseCircle(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case RECTANGLE:
- parseRectangle(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case LINE:
- parseLine(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- case POLYGON:
- parsePolygon(
- admLexer.getLastTokenImage().substring(1,
- admLexer.getLastTokenImage().length() - 1), out);
- break;
- default:
- throw new AsterixException("Missing deserializer method for constructor: "
- + AdmLexer.tokenKindToString(token) + ".");
-
+ if (token == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
+ if (targetTypeTag != typeTag) {
+ ITypePromoteComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag,
+ targetTypeTag);
+ // the availability if the promote computer should be consistent with the availability of a target type
+ assert promoteComputer != null;
+ // do the promotion; note that the type tag field should be skipped
+ promoteComputer.promote(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1,
+ castBuffer.getLength() - 1, out);
}
- token = admLexer.next();
- if (token == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE)
- return;
+ return;
}
}
}
- } catch (Exception e) {
- throw new AsterixException(e);
}
- throw new AsterixException(mismatchErrorMessage + objectType.getTypeName() + ". Got " + typeTag + " instead.");
+ throw new ParseException(mismatchErrorMessage + objectType.getTypeName() + ". Got " + typeTag + " instead.");
}
- private void parseBoolean(String bool, DataOutput out) throws AsterixException {
+ private boolean parseValue(final String unquoted, ATypeTag typeTag, DataOutput out) throws AsterixException,
+ HyracksDataException, IOException {
+ switch (typeTag) {
+ case BOOLEAN:
+ parseBoolean(unquoted, out);
+ return true;
+ case INT8:
+ parseInt8(unquoted, out);
+ return true;
+ case INT16:
+ parseInt16(unquoted, out);
+ return true;
+ case INT32:
+ parseInt32(unquoted, out);
+ return true;
+ case INT64:
+ parseInt64(unquoted, out);
+ return true;
+ case FLOAT:
+ aFloat.setValue(Float.parseFloat(unquoted));
+ floatSerde.serialize(aFloat, out);
+ return true;
+ case DOUBLE:
+ aDouble.setValue(Double.parseDouble(unquoted));
+ doubleSerde.serialize(aDouble, out);
+ return true;
+ case STRING:
+ aString.setValue(unquoted);
+ stringSerde.serialize(aString, out);
+ return true;
+ case TIME:
+ ATimeSerializerDeserializer.parse(unquoted, out);
+ return true;
+ case DATE:
+ ADateSerializerDeserializer.parse(unquoted, out);
+ return true;
+ case DATETIME:
+ ADateTimeSerializerDeserializer.parse(unquoted, out);
+ return true;
+ case DURATION:
+ ADurationSerializerDeserializer.parse(unquoted, out);
+ return true;
+ case DAYTIMEDURATION:
+ ADayTimeDurationSerializerDeserializer.INSTANCE.parse(unquoted, out);
+ return true;
+ case YEARMONTHDURATION:
+ AYearMonthDurationSerializerDeserializer.INSTANCE.parse(unquoted, out);
+ return true;
+ case POINT:
+ APointSerializerDeserializer.parse(unquoted, out);
+ return true;
+ case POINT3D:
+ APoint3DSerializerDeserializer.parse(unquoted, out);
+ return true;
+ case CIRCLE:
+ ACircleSerializerDeserializer.parse(unquoted, out);
+ return true;
+ case RECTANGLE:
+ ARectangleSerializerDeserializer.parse(unquoted, out);
+ return true;
+ case LINE:
+ ALineSerializerDeserializer.parse(unquoted, out);
+ return true;
+ case POLYGON:
+ APolygonSerializerDeserializer.parse(unquoted, out);
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ private void parseBoolean(String bool, DataOutput out) throws AsterixException, HyracksDataException {
String errorMessage = "This can not be an instance of boolean";
- try {
- if (bool.equals("true"))
- booleanSerde.serialize(ABoolean.TRUE, out);
- else if (bool.equals("false"))
- booleanSerde.serialize(ABoolean.FALSE, out);
- else
- throw new AsterixException(errorMessage);
- } catch (HyracksDataException e) {
- throw new AsterixException(errorMessage);
- }
+ if (bool.equals("true"))
+ booleanSerde.serialize(ABoolean.TRUE, out);
+ else if (bool.equals("false"))
+ booleanSerde.serialize(ABoolean.FALSE, out);
+ else
+ throw new ParseException(errorMessage);
}
- private void parseInt8(String int8, DataOutput out) throws AsterixException {
+ private void parseInt8(String int8, DataOutput out) throws AsterixException, HyracksDataException {
String errorMessage = "This can not be an instance of int8";
- try {
- boolean positive = true;
- byte value = 0;
- int offset = 0;
+ boolean positive = true;
+ byte value = 0;
+ int offset = 0;
- if (int8.charAt(offset) == '+')
- offset++;
- else if (int8.charAt(offset) == '-') {
- offset++;
- positive = false;
- }
- for (; offset < int8.length(); offset++) {
- if (int8.charAt(offset) >= '0' && int8.charAt(offset) <= '9')
- value = (byte) (value * 10 + int8.charAt(offset) - '0');
- else if (int8.charAt(offset) == 'i' && int8.charAt(offset + 1) == '8' && offset + 2 == int8.length())
- break;
- else
- throw new AsterixException(errorMessage);
- }
- if (value < 0)
- throw new AsterixException(errorMessage);
- if (value > 0 && !positive)
- value *= -1;
- aInt8.setValue(value);
- int8Serde.serialize(aInt8, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(errorMessage);
+ if (int8.charAt(offset) == '+')
+ offset++;
+ else if (int8.charAt(offset) == '-') {
+ offset++;
+ positive = false;
}
+ for (; offset < int8.length(); offset++) {
+ if (int8.charAt(offset) >= '0' && int8.charAt(offset) <= '9')
+ value = (byte) (value * 10 + int8.charAt(offset) - '0');
+ else if (int8.charAt(offset) == 'i' && int8.charAt(offset + 1) == '8' && offset + 2 == int8.length())
+ break;
+ else
+ throw new ParseException(errorMessage);
+ }
+ if (value < 0)
+ throw new ParseException(errorMessage);
+ if (value > 0 && !positive)
+ value *= -1;
+ aInt8.setValue(value);
+ int8Serde.serialize(aInt8, out);
}
- private void parseInt16(String int16, DataOutput out) throws AsterixException {
+ private void parseInt16(String int16, DataOutput out) throws AsterixException, HyracksDataException {
String errorMessage = "This can not be an instance of int16";
- try {
- boolean positive = true;
- short value = 0;
- int offset = 0;
+ boolean positive = true;
+ short value = 0;
+ int offset = 0;
- if (int16.charAt(offset) == '+')
- offset++;
- else if (int16.charAt(offset) == '-') {
- offset++;
- positive = false;
- }
- for (; offset < int16.length(); offset++) {
- if (int16.charAt(offset) >= '0' && int16.charAt(offset) <= '9')
- value = (short) (value * 10 + int16.charAt(offset) - '0');
- else if (int16.charAt(offset) == 'i' && int16.charAt(offset + 1) == '1'
- && int16.charAt(offset + 2) == '6' && offset + 3 == int16.length())
- break;
- else
- throw new AsterixException(errorMessage);
- }
- if (value < 0)
- throw new AsterixException(errorMessage);
- if (value > 0 && !positive)
- value *= -1;
- aInt16.setValue(value);
- int16Serde.serialize(aInt16, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(errorMessage);
+ if (int16.charAt(offset) == '+')
+ offset++;
+ else if (int16.charAt(offset) == '-') {
+ offset++;
+ positive = false;
}
+ for (; offset < int16.length(); offset++) {
+ if (int16.charAt(offset) >= '0' && int16.charAt(offset) <= '9')
+ value = (short) (value * 10 + int16.charAt(offset) - '0');
+ else if (int16.charAt(offset) == 'i' && int16.charAt(offset + 1) == '1' && int16.charAt(offset + 2) == '6'
+ && offset + 3 == int16.length())
+ break;
+ else
+ throw new ParseException(errorMessage);
+ }
+ if (value < 0)
+ throw new ParseException(errorMessage);
+ if (value > 0 && !positive)
+ value *= -1;
+ aInt16.setValue(value);
+ int16Serde.serialize(aInt16, out);
}
- private void parseInt32(String int32, DataOutput out) throws AsterixException {
-
+ private void parseInt32(String int32, DataOutput out) throws AsterixException, HyracksDataException {
String errorMessage = "This can not be an instance of int32";
- try {
- boolean positive = true;
- int value = 0;
- int offset = 0;
+ boolean positive = true;
+ int value = 0;
+ int offset = 0;
- if (int32.charAt(offset) == '+')
- offset++;
- else if (int32.charAt(offset) == '-') {
- offset++;
- positive = false;
- }
- for (; offset < int32.length(); offset++) {
- if (int32.charAt(offset) >= '0' && int32.charAt(offset) <= '9')
- value = (value * 10 + int32.charAt(offset) - '0');
- else if (int32.charAt(offset) == 'i' && int32.charAt(offset + 1) == '3'
- && int32.charAt(offset + 2) == '2' && offset + 3 == int32.length())
- break;
- else
- throw new AsterixException(errorMessage);
- }
- if (value < 0)
- throw new AsterixException(errorMessage);
- if (value > 0 && !positive)
- value *= -1;
-
- aInt32.setValue(value);
- int32Serde.serialize(aInt32, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(errorMessage);
+ if (int32.charAt(offset) == '+')
+ offset++;
+ else if (int32.charAt(offset) == '-') {
+ offset++;
+ positive = false;
}
+ for (; offset < int32.length(); offset++) {
+ if (int32.charAt(offset) >= '0' && int32.charAt(offset) <= '9')
+ value = (value * 10 + int32.charAt(offset) - '0');
+ else if (int32.charAt(offset) == 'i' && int32.charAt(offset + 1) == '3' && int32.charAt(offset + 2) == '2'
+ && offset + 3 == int32.length())
+ break;
+ else
+ throw new ParseException(errorMessage);
+ }
+ if (value < 0)
+ throw new ParseException(errorMessage);
+ if (value > 0 && !positive)
+ value *= -1;
+
+ aInt32.setValue(value);
+ int32Serde.serialize(aInt32, out);
}
- private void parseInt64(String int64, DataOutput out) throws AsterixException {
+ private void parseInt64(String int64, DataOutput out) throws AsterixException, HyracksDataException {
String errorMessage = "This can not be an instance of int64";
- try {
- boolean positive = true;
- long value = 0;
- int offset = 0;
+ boolean positive = true;
+ long value = 0;
+ int offset = 0;
- if (int64.charAt(offset) == '+')
- offset++;
- else if (int64.charAt(offset) == '-') {
- offset++;
- positive = false;
- }
- for (; offset < int64.length(); offset++) {
- if (int64.charAt(offset) >= '0' && int64.charAt(offset) <= '9')
- value = (value * 10 + int64.charAt(offset) - '0');
- else if (int64.charAt(offset) == 'i' && int64.charAt(offset + 1) == '6'
- && int64.charAt(offset + 2) == '4' && offset + 3 == int64.length())
- break;
- else
- throw new AsterixException(errorMessage);
- }
- if (value < 0)
- throw new AsterixException(errorMessage);
- if (value > 0 && !positive)
- value *= -1;
-
- aInt64.setValue(value);
- int64Serde.serialize(aInt64, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(errorMessage);
+ if (int64.charAt(offset) == '+')
+ offset++;
+ else if (int64.charAt(offset) == '-') {
+ offset++;
+ positive = false;
}
- }
-
- private void parsePoint(String point, DataOutput out) throws AsterixException {
- try {
- APointSerializerDeserializer.parse(point, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
+ for (; offset < int64.length(); offset++) {
+ if (int64.charAt(offset) >= '0' && int64.charAt(offset) <= '9')
+ value = (value * 10 + int64.charAt(offset) - '0');
+ else if (int64.charAt(offset) == 'i' && int64.charAt(offset + 1) == '6' && int64.charAt(offset + 2) == '4'
+ && offset + 3 == int64.length())
+ break;
+ else
+ throw new ParseException(errorMessage);
}
- }
+ if (value < 0)
+ throw new ParseException(errorMessage);
+ if (value > 0 && !positive)
+ value *= -1;
- private void parsePoint3d(String point3d, DataOutput out) throws AsterixException {
- try {
- APoint3DSerializerDeserializer.parse(point3d, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
- }
+ aInt64.setValue(value);
+ int64Serde.serialize(aInt64, out);
}
-
- private void parseCircle(String circle, DataOutput out) throws AsterixException {
- try {
- ACircleSerializerDeserializer.parse(circle, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
- }
- }
-
- private void parseRectangle(String rectangle, DataOutput out) throws AsterixException {
- try {
- ARectangleSerializerDeserializer.parse(rectangle, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
- }
- }
-
- private void parseLine(String line, DataOutput out) throws AsterixException {
- try {
- ALineSerializerDeserializer.parse(line, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
- }
- }
-
- private void parsePolygon(String polygon, DataOutput out) throws AsterixException, IOException {
- try {
- APolygonSerializerDeserializer.parse(polygon, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
- }
- }
-
- private void parseTime(String time, DataOutput out) throws AsterixException {
- try {
- ATimeSerializerDeserializer.parse(time, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
- }
- }
-
- private void parseDate(String date, DataOutput out) throws AsterixException, IOException {
- try {
- ADateSerializerDeserializer.parse(date, out);
- } catch (HyracksDataException e) {
- throw new AsterixException(e);
- }
- }
-
}