You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by am...@apache.org on 2018/06/04 06:15:06 UTC

[2/2] asterixdb git commit: Merge commit '2a182c495d311757f1aa9291ca407c8068f00ff2' from release-0.9.4-pre-rc

Merge commit '2a182c495d311757f1aa9291ca407c8068f00ff2' from release-0.9.4-pre-rc

Change-Id: I69cf41237858ecbca4d89e8f0403e0f443101539


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

Branch: refs/heads/master
Commit: b54f9bffa01a30e900a1aaf419e5ec137d0facc6
Parents: 5c26b42 2a182c4
Author: Michael Blow <mb...@apache.org>
Authored: Sun Jun 3 14:29:26 2018 -0400
Committer: Michael Blow <mb...@apache.org>
Committed: Sun Jun 3 14:29:26 2018 -0400

----------------------------------------------------------------------
 .../external/parser/test/ADMDataParserTest.java | 45 ++++++++++++++------
 1 file changed, 32 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/b54f9bff/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/parser/test/ADMDataParserTest.java
----------------------------------------------------------------------
diff --cc asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/parser/test/ADMDataParserTest.java
index a4e4c33,1485f4f..189c842
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/parser/test/ADMDataParserTest.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/parser/test/ADMDataParserTest.java
@@@ -23,14 -22,12 +23,17 @@@ import java.io.ByteArrayOutputStream
  import java.io.DataOutput;
  import java.io.DataOutputStream;
  import java.io.IOException;
 +import java.io.InputStream;
+ import java.lang.reflect.Field;
+ import java.lang.reflect.Method;
 +import java.nio.ByteBuffer;
  import java.util.concurrent.atomic.AtomicInteger;
  
  import org.apache.asterix.external.parser.ADMDataParser;
+ import org.apache.asterix.external.parser.AbstractDataParser;
 +import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
 +import org.apache.asterix.om.base.AGeometry;
 +import org.apache.asterix.om.base.AInt32;
  import org.apache.asterix.om.base.AMutableDate;
  import org.apache.asterix.om.base.AMutableDateTime;
  import org.apache.asterix.om.base.AMutableTime;
@@@ -43,16 -34,11 +46,14 @@@ import org.apache.hyracks.api.dataflow.
  import org.junit.Assert;
  import org.junit.Test;
  
 +import com.esri.core.geometry.ogc.OGCPoint;
 +
- import junit.extensions.PA;
- 
  public class ADMDataParserTest {
  
      @Test
-     public void test() throws IOException {
+     public void test() throws IOException, NoSuchMethodException, SecurityException, NoSuchFieldException {
 -        String[] dates = { "-9537-08-04", "9656-06-03", "-9537-04-04", "9656-06-04", "-9537-10-04", "9626-09-05" };
 +        char[][] dates = toChars(
 +                new String[] { "-9537-08-04", "9656-06-03", "-9537-04-04", "9656-06-04", "-9537-10-04", "9626-09-05" });
          AMutableDate[] parsedDates =
                  new AMutableDate[] { new AMutableDate(-4202630), new AMutableDate(2807408), new AMutableDate(-4202752),
                          new AMutableDate(2807409), new AMutableDate(-4202569), new AMutableDate(2796544), };
@@@ -71,6 -56,27 +72,27 @@@
                          new AMutableDateTime(-45286270768513L), new AMutableDateTime(151729886421653L),
                          new AMutableDateTime(5047449515758L), new AMutableDateTime(210721439419691L) };
  
 -        Method parseDateMethod =
 -                AbstractDataParser.class.getDeclaredMethod("parseDate", String.class, DataOutput.class);
++        Method parseDateMethod = AbstractDataParser.class.getDeclaredMethod("parseDate", char[].class, int.class,
++                int.class, DataOutput.class);
+         parseDateMethod.setAccessible(true);
+ 
+         Field aDateField = AbstractDataParser.class.getDeclaredField("aDate");
+         aDateField.setAccessible(true);
+ 
 -        Method parseTimeMethod =
 -                AbstractDataParser.class.getDeclaredMethod("parseTime", String.class, DataOutput.class);
++        Method parseTimeMethod = AbstractDataParser.class.getDeclaredMethod("parseTime", char[].class, int.class,
++                int.class, DataOutput.class);
+         parseTimeMethod.setAccessible(true);
+ 
+         Field aTimeField = AbstractDataParser.class.getDeclaredField("aTime");
+         aTimeField.setAccessible(true);
+ 
 -        Method parseDateTimeMethod =
 -                AbstractDataParser.class.getDeclaredMethod("parseDateTime", String.class, DataOutput.class);
++        Method parseDateTimeMethod = AbstractDataParser.class.getDeclaredMethod("parseDateTime", char[].class,
++                int.class, int.class, DataOutput.class);
+         parseDateTimeMethod.setAccessible(true);
+ 
+         Field aDateTimeField = AbstractDataParser.class.getDeclaredField("aDateTime");
+         aDateTimeField.setAccessible(true);
+ 
          Thread[] threads = new Thread[16];
          AtomicInteger errorCount = new AtomicInteger(0);
          for (int i = 0; i < threads.length; ++i) {
@@@ -86,25 -92,22 +108,22 @@@
                          while (round++ < 10000) {
                              // Test parseDate.
                              for (int index = 0; index < dates.length; ++index) {
-                                 PA.invokeMethod(parser, "parseDate(char[], int, int, java.io.DataOutput)", dates[index],
-                                         0, dates[index].length, dos);
-                                 AMutableDate aDate = (AMutableDate) PA.getValue(parser, "aDate");
 -                                parseDateMethod.invoke(parser, dates[index], dos);
++                                parseDateMethod.invoke(parser, dates[index], 0, dates[index].length, dos);
+                                 AMutableDate aDate = (AMutableDate) aDateField.get(parser);
                                  Assert.assertTrue(aDate.equals(parsedDates[index]));
                              }
  
                              // Tests parseTime.
                              for (int index = 0; index < times.length; ++index) {
-                                 PA.invokeMethod(parser, "parseTime(char[], int, int, java.io.DataOutput)", times[index],
-                                         0, times[index].length, dos);
-                                 AMutableTime aTime = (AMutableTime) PA.getValue(parser, "aTime");
 -                                parseTimeMethod.invoke(parser, times[index], dos);
++                                parseTimeMethod.invoke(parser, times[index], 0, times[index].length, dos);
+                                 AMutableTime aTime = (AMutableTime) aTimeField.get(parser);
                                  Assert.assertTrue(aTime.equals(parsedTimes[index]));
                              }
  
                              // Tests parseDateTime.
                              for (int index = 0; index < dateTimes.length; ++index) {
-                                 PA.invokeMethod(parser, "parseDateTime(char[], int, int, java.io.DataOutput)",
-                                         dateTimes[index], 0, dateTimes[index].length, dos);
-                                 AMutableDateTime aDateTime = (AMutableDateTime) PA.getValue(parser, "aDateTime");
 -                                parseDateTimeMethod.invoke(parser, dateTimes[index], dos);
++                                parseDateTimeMethod.invoke(parser, dateTimes[index], 0, dateTimes[index].length, dos);
+                                 AMutableDateTime aDateTime = (AMutableDateTime) aDateTimeField.get(parser);
                                  Assert.assertTrue(aDateTime.equals(parsedDateTimes[index]));
                              }
                          }
@@@ -129,58 -132,4 +148,58 @@@
          // Asserts no failure.
          Assert.assertTrue(errorCount.get() == 0);
      }
 -}
 +
 +    private char[][] toChars(String[] strings) {
 +        char[][] results = new char[strings.length][];
 +        for (int i = 0; i < strings.length; i++) {
 +            results[i] = strings[i].toCharArray();
 +        }
 +        return results;
 +    }
 +
 +    @Test
 +    public void testWKTParser() {
 +        try {
 +            ARecordType recordType = new ARecordType("POIType", new String[] { "id", "coord" },
 +                    new IAType[] { BuiltinType.AINT32, BuiltinType.AGEOMETRY }, false);
 +
 +            String wktObject = "{\"id\": 123, \"coord\": \"POINT(3 4)\"}";
 +            InputStream in = new ByteArrayInputStream(wktObject.getBytes());
 +            ADMDataParser parser = new ADMDataParser(recordType, true);
 +            parser.setInputStream(in);
 +            ByteArrayOutputStream baos = new ByteArrayOutputStream();
 +            DataOutputStream out = new DataOutputStream(baos);
 +            parser.parse(out);
 +            out.close();
 +            byte[] serialized = baos.toByteArray();
 +
 +            // Parse to make sure it was correct
 +            ByteBuffer bb = ByteBuffer.wrap(serialized);
 +            Assert.assertEquals(ATypeTag.SERIALIZED_RECORD_TYPE_TAG, bb.get());
 +            Assert.assertEquals(serialized.length, bb.getInt()); // Total record size including header
 +            Assert.assertEquals(2, bb.getInt()); // # of records
 +            int offsetOfID = bb.getInt();
 +            int offsetOfGeometry = bb.getInt();
 +            ISerializerDeserializer intDeser =
 +                    SerializerDeserializerProvider.INSTANCE.getNonTaggedSerializerDeserializer(BuiltinType.AINT32);
 +            Assert.assertEquals(offsetOfID, bb.position());
 +            // Serialize the two records
 +            DataInputByteBuffer dataIn = new DataInputByteBuffer();
 +            dataIn.reset(bb);
 +            Object o = intDeser.deserialize(dataIn);
 +            Assert.assertEquals(new AInt32(123), o);
 +            ISerializerDeserializer geomDeser =
 +                    SerializerDeserializerProvider.INSTANCE.getNonTaggedSerializerDeserializer(BuiltinType.AGEOMETRY);
 +            Object point = geomDeser.deserialize(dataIn);
 +            Assert.assertTrue(point instanceof AGeometry);
 +            Assert.assertTrue(((AGeometry) point).getGeometry() instanceof OGCPoint);
 +            OGCPoint p = (OGCPoint) ((AGeometry) point).getGeometry();
 +            Assert.assertEquals(3.0, p.X(), 1E-5);
 +            Assert.assertEquals(4.0, p.Y(), 1E-5);
 +        } catch (IOException e) {
 +            e.printStackTrace();
 +            Assert.fail("Error in parsing");
 +        }
 +
 +    }
- }
++}