asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject asterixdb git commit: small ADMParser/AdmLexer cleanup
Date Mon, 01 Aug 2016 06:08:52 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master ef3f02761 -> 19d30853e


small ADMParser/AdmLexer cleanup

- do not declare IOExceptions that are not thrown
- improve formatting of lexer template

Change-Id: Id032f0c83ebef108a9eddb7242c586d5481217e4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1032
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>


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

Branch: refs/heads/master
Commit: 19d30853ec8392fe68e4da9b0ec4f9aaf68adf8e
Parents: ef3f027
Author: Till Westmann <tillw@apache.org>
Authored: Thu Jul 28 23:27:58 2016 -0700
Committer: Till Westmann <tillw@apache.org>
Committed: Sun Jul 31 23:08:18 2016 -0700

----------------------------------------------------------------------
 .../asterix/external/parser/ADMDataParser.java  |   4 +-
 .../parser/factory/ADMDataParserFactory.java    |  15 +-
 .../adapter/TestTypedAdapterFactory.java        |  18 +--
 .../src/main/resources/Lexer.java               | 136 +++++++++----------
 4 files changed, 81 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/19d30853/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
index 58d7c83..eb81d3f 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
@@ -124,11 +124,11 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
         }
     }
 
-    public ADMDataParser(ARecordType recordType, boolean isStream) throws IOException {
+    public ADMDataParser(ARecordType recordType, boolean isStream) {
         this(null, recordType, isStream);
     }
 
-    public ADMDataParser(String filename, ARecordType recordType, boolean isStream) throws
IOException {
+    public ADMDataParser(String filename, ARecordType recordType, boolean isStream) {
         this.filename = filename;
         this.recordType = recordType;
         this.isStreamParser = isStream;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/19d30853/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/ADMDataParserFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/ADMDataParserFactory.java
b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/ADMDataParserFactory.java
index 7732820..efc9574 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/ADMDataParserFactory.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/ADMDataParserFactory.java
@@ -18,9 +18,9 @@
  */
 package org.apache.asterix.external.parser.factory;
 
-import org.apache.asterix.external.api.IExternalDataSourceFactory.DataSourceType;
 import org.apache.asterix.external.api.IRecordDataParser;
 import org.apache.asterix.external.api.IStreamDataParser;
+import org.apache.asterix.external.api.IExternalDataSourceFactory.DataSourceType;
 import org.apache.asterix.external.parser.ADMDataParser;
 import org.apache.asterix.external.util.ExternalDataUtils;
 import org.apache.asterix.om.types.ARecordType;
@@ -32,18 +32,13 @@ public class ADMDataParserFactory extends AbstractRecordStreamParserFactory<char
     private static final long serialVersionUID = 1L;
 
     @Override
-    public IRecordDataParser<char[]> createRecordParser(IHyracksTaskContext ctx) throws
HyracksDataException {
+    public IRecordDataParser<char[]> createRecordParser(IHyracksTaskContext ctx) {
         return createParser();
     }
 
-    private ADMDataParser createParser() throws HyracksDataException {
-        try {
-            ADMDataParser parser = new ADMDataParser(recordType,
-                    ExternalDataUtils.getDataSourceType(configuration).equals(DataSourceType.STREAM));
-            return parser;
-        } catch (Exception e) {
-            throw new HyracksDataException(e);
-        }
+    private ADMDataParser createParser() {
+        return new ADMDataParser(recordType,
+                ExternalDataUtils.getDataSourceType(configuration).equals(DataSourceType.STREAM));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/19d30853/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/adapter/TestTypedAdapterFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/adapter/TestTypedAdapterFactory.java
b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/adapter/TestTypedAdapterFactory.java
index 6850c2b..d45097a 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/adapter/TestTypedAdapterFactory.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/adapter/TestTypedAdapterFactory.java
@@ -83,18 +83,12 @@ public class TestTypedAdapterFactory implements IAdapterFactory {
                                 .getApplicationObject();
                 ClusterPartition nodePartition = propertiesProvider.getMetadataProperties().getNodePartitions()
                         .get(nodeId)[0];
-                try {
-                    parser = new ADMDataParser(outputType, true);
-                    forwarder = DataflowUtils
-                            .getTupleForwarder(configuration,
-                                    FeedUtils.getFeedLogManager(ctx,
-                                            FeedUtils.splitsForAdapter(ExternalDataUtils.getDataverse(configuration),
-                                                    ExternalDataUtils.getFeedName(configuration),
nodeId,
-                                                    nodePartition)));
-                    tb = new ArrayTupleBuilder(1);
-                } catch (Exception e) {
-                    throw new HyracksDataException(e);
-                }
+                parser = new ADMDataParser(outputType, true);
+                forwarder = DataflowUtils.getTupleForwarder(configuration,
+                        FeedUtils.getFeedLogManager(ctx,
+                                FeedUtils.splitsForAdapter(ExternalDataUtils.getDataverse(configuration),
+                                        ExternalDataUtils.getFeedName(configuration), nodeId,
nodePartition)));
+                tb = new ArrayTupleBuilder(1);
                 return new ITupleParser() {
 
                     @Override

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/19d30853/asterixdb/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
b/asterixdb/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
index 495a95e..3613166 100644
--- a/asterixdb/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
+++ b/asterixdb/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
@@ -73,22 +73,22 @@ public class [LEXER_NAME] {
 //  Public interface
 // ================================================================================
 
-    public [LEXER_NAME](java.io.Reader stream) throws IOException{
+    public [LEXER_NAME](java.io.Reader stream) throws IOException {
         reInit(stream);
     }
 
-    public [LEXER_NAME]() throws IOException{
+    public [LEXER_NAME]() {
         reInit();
     }
 
-    public void setBuffer(char[] buffer){
+    public void setBuffer(char[] buffer) {
         this.buffer = buffer;
         tokenBegin = bufpos = 0;
         containsEscapes = false;
         tokenBegin = -1;
     }
 
-    public void reInit(){
+    public void reInit() {
         bufsize        = Integer.MAX_VALUE;
         endOf_UNUSED_Buffer = bufsize;
         endOf_USED_Buffer = bufsize;
@@ -99,7 +99,7 @@ public class [LEXER_NAME] {
         maxUnusedBufferSize = bufsize;
     }
 
-    public void reInit(java.io.Reader stream) throws IOException{
+    public void reInit(java.io.Reader stream) throws IOException {
         done();
         inputStream    = stream;
         bufsize        = 4096;
@@ -117,11 +117,11 @@ public class [LEXER_NAME] {
     }
 
     public String getLastTokenImage() {
-        if (bufpos >= tokenBegin)
+        if (bufpos >= tokenBegin) {
             return new String(buffer, tokenBegin, bufpos - tokenBegin);
-          else
-            return new String(buffer, tokenBegin, bufsize - tokenBegin) +
-                                  new String(buffer, 0, bufpos);
+        } else {
+            return new String(buffer, tokenBegin, bufsize - tokenBegin) + new String(buffer,
0, bufpos);
+        }
     }
 
     public int getColumn() {
@@ -163,27 +163,21 @@ public class [LEXER_NAME] {
     protected void updateLineColumn(char c){
         column++;
 
-        if (prevCharIsLF)
-        {
+        if (prevCharIsLF) {
             prevCharIsLF = false;
             line += (column = 1);
-        }
-        else if (prevCharIsCR)
-        {
+        } else if (prevCharIsCR) {
             prevCharIsCR = false;
-            if (c == '\n')
-            {
+            if (c == '\n') {
                 prevCharIsLF = true;
-            }
-            else
-            {
+            } else {
                 line += (column = 1);
             }
         }
 
         if (c=='\r') {
             prevCharIsCR = true;
-        } else if(c == '\n') {
+        } else if (c == '\n') {
             prevCharIsLF = true;
         }
     }
@@ -193,73 +187,79 @@ public class [LEXER_NAME] {
 // ================================================================================
 
     protected char readNextChar() throws IOException {
-        if (++bufpos >= endOf_USED_Buffer)
+        if (++bufpos >= endOf_USED_Buffer) {
             fillBuff();
+        }
         char c = buffer[bufpos];
         updateLineColumn(c);
         return c;
     }
 
     protected boolean fillBuff() throws IOException {
-        if (endOf_UNUSED_Buffer == endOf_USED_Buffer) // If no more unused buffer space
-        {
-          if (endOf_UNUSED_Buffer == bufsize)         // -- If the previous unused space
was
-          {                                           // -- at the end of the buffer
-            if (tokenBegin > maxUnusedBufferSize)     // -- -- If the first N bytes before
-            {                                         //       the current token are enough
-              bufpos = endOf_USED_Buffer = 0;         // -- -- -- setup buffer to use that
fragment
-              endOf_UNUSED_Buffer = tokenBegin;
+        if (endOf_UNUSED_Buffer == endOf_USED_Buffer) {
+            // If no more unused buffer space
+            if (endOf_UNUSED_Buffer == bufsize) {
+                // If the previous unused space was at the end of the buffer
+                if (tokenBegin > maxUnusedBufferSize) {
+                    // If the first N bytes before the current token are enough
+                    // setup buffer to use that fragment
+                    bufpos = endOf_USED_Buffer = 0;
+                    endOf_UNUSED_Buffer = tokenBegin;
+                } else if (tokenBegin < 0){
+                    // If no token yet
+                    // reuse the whole buffer
+                    bufpos = endOf_USED_Buffer = 0;
+                } else {
+                    // Otherwise expand buffer after its end
+                    ExpandBuff(false);
+                }
+            } else if (endOf_UNUSED_Buffer > tokenBegin){
+                // If the endOf_UNUSED_Buffer is after the token
+                // set endOf_UNUSED_Buffer to the end of the buffer
+                endOf_UNUSED_Buffer = bufsize;
+            } else if ((tokenBegin - endOf_UNUSED_Buffer) < maxUnusedBufferSize) {
+                // If between endOf_UNUSED_Buffer and the token there is NOT enough space
expand the buffer
+                // reorganizing it
+                ExpandBuff(true);
+            } else {
+                // Otherwise there is enough space at the start
+                // so we set the buffer to use that fragment
+                endOf_UNUSED_Buffer = tokenBegin;
             }
-            else if (tokenBegin < 0)                  // -- -- If no token yet
-              bufpos = endOf_USED_Buffer = 0;         // -- -- -- reuse the whole buffer
-            else
-              ExpandBuff(false);                      // -- -- Otherwise expand buffer after
its end
-          }
-          else if (endOf_UNUSED_Buffer > tokenBegin)  // If the endOf_UNUSED_Buffer is
after the token
-            endOf_UNUSED_Buffer = bufsize;            // -- set endOf_UNUSED_Buffer to the
end of the buffer
-          else if ((tokenBegin - endOf_UNUSED_Buffer) < maxUnusedBufferSize)
-          {                                           // If between endOf_UNUSED_Buffer and
the token
-            ExpandBuff(true);                         // there is NOT enough space expand
the buffer
-          }                                           // reorganizing it
-          else
-            endOf_UNUSED_Buffer = tokenBegin;         // Otherwise there is enough space
at the start
-        }                                             // so we set the buffer to use that
fragment
+        }
         int i;
-        if ((i = inputStream.read(buffer, endOf_USED_Buffer, endOf_UNUSED_Buffer - endOf_USED_Buffer))
== -1)
-        {
+        if ((i = inputStream.read(buffer, endOf_USED_Buffer, endOf_UNUSED_Buffer - endOf_USED_Buffer))
== -1) {
             inputStream.close();
-            buffer[endOf_USED_Buffer]=(char)EOF_CHAR;
+            buffer[endOf_USED_Buffer] = (char)EOF_CHAR;
             endOf_USED_Buffer++;
             return false;
+        } else {
+            endOf_USED_Buffer += i;
         }
-            else
-                endOf_USED_Buffer += i;
         return true;
     }
 
 
-    protected void ExpandBuff(boolean wrapAround)
-    {
-      char[] newbuffer = new char[bufsize + maxUnusedBufferSize];
+    protected void ExpandBuff(boolean wrapAround) {
+        char[] newbuffer = new char[bufsize + maxUnusedBufferSize];
 
-      try {
-        if (wrapAround) {
-          System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
-          System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
-          buffer = newbuffer;
-          endOf_USED_Buffer = (bufpos += (bufsize - tokenBegin));
-        }
-        else {
-          System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
-          buffer = newbuffer;
-          endOf_USED_Buffer = (bufpos -= tokenBegin);
+        try {
+            if (wrapAround) {
+                System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+                System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
+                buffer = newbuffer;
+                endOf_USED_Buffer = (bufpos += (bufsize - tokenBegin));
+            } else {
+                System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+                buffer = newbuffer;
+                endOf_USED_Buffer = (bufpos -= tokenBegin);
+            }
+        } catch (Throwable t) {
+            throw new Error(t.getMessage());
         }
-      } catch (Throwable t) {
-          throw new Error(t.getMessage());
-      }
 
-      bufsize += maxUnusedBufferSize;
-      endOf_UNUSED_Buffer = bufsize;
-      tokenBegin = 0;
+        bufsize += maxUnusedBufferSize;
+        endOf_UNUSED_Buffer = bufsize;
+        tokenBegin = 0;
     }
 }


Mime
View raw message