hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shiv...@apache.org
Subject [05/15] incubator-hawq git commit: HAWQ-45. PXF package namespace refactor
Date Tue, 03 Nov 2015 00:36:08 GMT
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/HiveMetadataFetcherTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/HiveMetadataFetcherTest.java b/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/HiveMetadataFetcherTest.java
new file mode 100644
index 0000000..b14061c
--- /dev/null
+++ b/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/HiveMetadataFetcherTest.java
@@ -0,0 +1,142 @@
+package org.apache.hawq.pxf.plugins.hive;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+import org.apache.hawq.pxf.api.Metadata;
+import org.apache.hawq.pxf.plugins.hive.utilities.HiveUtilities;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({HiveMetadataFetcher.class}) // Enables mocking 'new' calls
+@SuppressStaticInitializationFor({"org.apache.hadoop.hive.metastore.api.MetaException",
+"org.apache.hawq.pxf.plugins.hive.utilities.HiveUtilities"}) // Prevents static inits
+public class HiveMetadataFetcherTest {
+
+    Log LOG;
+    HiveConf hiveConfiguration;
+    HiveMetaStoreClient hiveClient;
+    HiveMetadataFetcher fetcher;
+    Metadata metadata;
+
+    @Before
+    public void SetupCompressionFactory() {
+        LOG = mock(Log.class);
+        Whitebox.setInternalState(HiveUtilities.class, LOG);
+    }
+
+    @Test
+    public void construction() throws Exception {
+        prepareConstruction();
+        fetcher = new HiveMetadataFetcher();
+        PowerMockito.verifyNew(HiveMetaStoreClient.class).withArguments(hiveConfiguration);
+    }
+
+    @Test
+    public void constructorCantAccessMetaStore() throws Exception {
+        prepareConstruction();
+        PowerMockito.whenNew(HiveMetaStoreClient.class).withArguments(hiveConfiguration).thenThrow(new MetaException("which way to albuquerque"));
+
+        try {
+            fetcher = new HiveMetadataFetcher();
+            fail("Expected a RuntimeException");
+        } catch (RuntimeException ex) {
+            assertEquals("Failed connecting to Hive MetaStore service: which way to albuquerque", ex.getMessage());
+        }
+    }
+
+    @Test
+    public void getTableMetadataInvalidTableName() throws Exception {
+        prepareConstruction();
+        fetcher = new HiveMetadataFetcher();
+        String tableName = "t.r.o.u.b.l.e.m.a.k.e.r";
+
+        try {
+            fetcher.getTableMetadata(tableName);
+            fail("Expected an IllegalArgumentException");
+        } catch (IllegalArgumentException ex) {
+            assertEquals("\"t.r.o.u.b.l.e.m.a.k.e.r\" is not a valid Hive table name. Should be either <table_name> or <db_name.table_name>", ex.getMessage()); 
+        }
+    }
+
+    @Test
+    public void getTableMetadataView() throws Exception {
+        prepareConstruction();
+
+        fetcher = new HiveMetadataFetcher();
+        String tableName = "cause";
+
+        // mock hive table returned from hive client
+        Table hiveTable = new Table();
+        hiveTable.setTableType("VIRTUAL_VIEW");
+        when(hiveClient.getTable("default", tableName)).thenReturn(hiveTable);
+
+        try {
+            metadata = fetcher.getTableMetadata(tableName);
+            fail("Expected an UnsupportedOperationException because PXF doesn't support views");
+        } catch (UnsupportedOperationException e) {
+            assertEquals("Hive views are not supported by HAWQ", e.getMessage());
+        }
+    }
+
+    @Test
+    public void getTableMetadata() throws Exception {
+        prepareConstruction();
+
+        fetcher = new HiveMetadataFetcher();
+        String tableName = "cause";
+
+        // mock hive table returned from hive client
+        List<FieldSchema> fields = new ArrayList<FieldSchema>();
+        fields.add(new FieldSchema("field1", "string", null));
+        fields.add(new FieldSchema("field2", "int", null));
+        StorageDescriptor sd = new StorageDescriptor();
+        sd.setCols(fields);
+        Table hiveTable = new Table();
+        hiveTable.setTableType("MANAGED_TABLE");
+        hiveTable.setSd(sd);
+        hiveTable.setPartitionKeys(new ArrayList<FieldSchema>());
+        when(hiveClient.getTable("default", tableName)).thenReturn(hiveTable);
+
+        // get metadata
+        metadata = fetcher.getTableMetadata(tableName);
+
+        assertEquals("default.cause", metadata.getTable().toString());
+
+        List<Metadata.Field> resultFields = metadata.getFields();
+        assertNotNull(resultFields);
+        assertEquals(2, resultFields.size());
+        Metadata.Field field = resultFields.get(0);
+        assertEquals("field1", field.getName());
+        assertEquals("text", field.getType()); // converted type
+        field = resultFields.get(1);
+        assertEquals("field2", field.getName());
+        assertEquals("int4", field.getType());
+    }
+
+    private void prepareConstruction() throws Exception {
+        hiveConfiguration = mock(HiveConf.class);
+        PowerMockito.whenNew(HiveConf.class).withNoArguments().thenReturn(hiveConfiguration);
+
+        hiveClient = mock(HiveMetaStoreClient.class);
+        PowerMockito.whenNew(HiveMetaStoreClient.class).withArguments(hiveConfiguration).thenReturn(hiveClient);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilitiesTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilitiesTest.java b/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilitiesTest.java
new file mode 100644
index 0000000..12ea9db
--- /dev/null
+++ b/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilitiesTest.java
@@ -0,0 +1,195 @@
+package org.apache.hawq.pxf.plugins.hive.utilities;
+
+import static org.junit.Assert.*;
+
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.junit.Test;
+
+import org.apache.hawq.pxf.api.Metadata;
+import org.apache.hawq.pxf.api.UnsupportedTypeException;
+
+public class HiveUtilitiesTest {
+
+    FieldSchema hiveColumn;
+    Metadata.Table tblDesc;
+
+    static String[][] typesMappings = {
+        /* hive type -> hawq type */
+        {"tinyint", "int2"},
+        {"smallint", "int2"},
+        {"int", "int4"},
+        {"bigint", "int8"},
+        {"boolean", "bool"},
+        {"float", "float4"},
+        {"double", "float8"},
+        {"string", "text"},
+        {"binary", "bytea"},
+        {"timestamp", "timestamp"},
+        {"date", "date"},
+    };
+
+    static String[][] typesWithModifiers = {
+        {"decimal(19,84)", "numeric", "19,84"},
+        {"varchar(13)", "varchar", "13"},
+        {"char(40)", "bpchar", "40"},
+    };
+
+    @Test
+    public void mapHiveTypeUnsupported() throws Exception {
+
+        hiveColumn = new FieldSchema("complex", "array", null);
+
+        try {
+            HiveUtilities.mapHiveType(hiveColumn);
+            fail("unsupported type");
+        } catch (UnsupportedTypeException e) {
+            assertEquals("HAWQ does not support type " + hiveColumn.getType() + " (Field " + hiveColumn.getName() + ")",
+                    e.getMessage());
+        }
+    }
+
+    @Test
+    public void mapHiveTypeSimple() throws Exception {
+        /*
+         * tinyint -> int2
+         * smallint -> int2
+         * int -> int4
+         * bigint -> int8
+         * boolean -> bool
+         * float -> float4
+         * double -> float8
+         * string -> text
+         * binary -> bytea
+         * timestamp -> timestamp
+         * date -> date
+         */
+        for (String[] line: typesMappings) {
+            String hiveType = line[0];
+            String expectedType = line[1];
+            hiveColumn = new FieldSchema("field" + hiveType, hiveType, null);
+            Metadata.Field result = HiveUtilities.mapHiveType(hiveColumn);
+            assertEquals("field" + hiveType, result.getName());
+            assertEquals(expectedType, result.getType());
+            assertNull(result.getModifiers());
+        }
+    }
+
+    @Test
+    public void mapHiveTypeWithModifiers() throws Exception {
+        /*
+         * decimal -> numeric
+         * varchar -> varchar
+         * char -> bpchar
+         */
+        for (String[] line: typesWithModifiers) {
+            String hiveType = line[0];
+            String expectedType = line[1];
+            String modifiersStr = line[2];
+            String[] expectedModifiers = modifiersStr.split(",");
+            hiveColumn = new FieldSchema("field" + hiveType, hiveType, null);
+            Metadata.Field result = HiveUtilities.mapHiveType(hiveColumn);
+            assertEquals("field" + hiveType, result.getName());
+            assertEquals(expectedType, result.getType());
+            assertArrayEquals(expectedModifiers, result.getModifiers());
+        }
+    }
+
+    @Test
+    public void mapHiveTypeWithModifiersNegative() throws Exception {
+
+        String badHiveType = "decimal(2)";
+        hiveColumn = new FieldSchema("badNumeric", badHiveType, null);
+        try {
+            HiveUtilities.mapHiveType(hiveColumn);
+            fail("should fail with bad numeric type error");
+        } catch (UnsupportedTypeException e) {
+            String errorMsg = "HAWQ does not support type " + badHiveType + " (Field badNumeric), " +
+                "expected type of the form <type name>(<parameter>,<parameter>)";
+            assertEquals(errorMsg, e.getMessage());
+        }
+
+        badHiveType = "char(1,2,3)";
+        hiveColumn = new FieldSchema("badChar", badHiveType, null);
+        try {
+            HiveUtilities.mapHiveType(hiveColumn);
+            fail("should fail with bad char type error");
+        } catch (UnsupportedTypeException e) {
+            String errorMsg = "HAWQ does not support type " + badHiveType + " (Field badChar), " +
+                "expected type of the form <type name>(<parameter>)";
+            assertEquals(errorMsg, e.getMessage());
+        }
+
+        badHiveType = "char(acter)";
+        hiveColumn = new FieldSchema("badModifier", badHiveType, null);
+        try {
+            HiveUtilities.mapHiveType(hiveColumn);
+            fail("should fail with bad modifier error");
+        } catch (UnsupportedTypeException e) {
+            String errorMsg = "HAWQ does not support type " + badHiveType + " (Field badModifier), " +
+                "modifiers should be integers";
+            assertEquals(errorMsg, e.getMessage());
+        }
+    }
+
+    @Test
+    public void parseTableQualifiedNameNoDbName() throws Exception {
+        String name = "orphan";
+        tblDesc = HiveUtilities.parseTableQualifiedName(name);
+
+        assertEquals("default", tblDesc.getDbName());
+        assertEquals(name, tblDesc.getTableName());
+    }
+
+    @Test
+    public void parseTableQualifiedName() throws Exception {
+        String name = "not.orphan";
+        tblDesc = HiveUtilities.parseTableQualifiedName(name);
+
+        assertEquals("not", tblDesc.getDbName());
+        assertEquals("orphan", tblDesc.getTableName());
+    }
+
+    @Test
+    public void parseTableQualifiedNameTooManyQualifiers() throws Exception {
+        String name = "too.many.parents";
+        String errorMsg = surroundByQuotes(name) + " is not a valid Hive table name. "
+                + "Should be either <table_name> or <db_name.table_name>";
+
+        parseTableQualifiedNameNegative(name, errorMsg, "too many qualifiers");
+    }
+
+    @Test
+    public void parseTableQualifiedNameEmpty() throws Exception {
+        String name = "";
+        String errorMsg = "empty string is not a valid Hive table name. "
+                + "Should be either <table_name> or <db_name.table_name>";
+
+        parseTableQualifiedNameNegative(name, errorMsg, "empty string");
+
+        name = null;
+        parseTableQualifiedNameNegative(name, errorMsg, "null string");
+
+        name = ".";
+        errorMsg = surroundByQuotes(name) + " is not a valid Hive table name. "
+                + "Should be either <table_name> or <db_name.table_name>";
+        parseTableQualifiedNameNegative(name, errorMsg, "empty db and table names");
+
+        name = " . ";
+        errorMsg = surroundByQuotes(name) + " is not a valid Hive table name. "
+                + "Should be either <table_name> or <db_name.table_name>";
+        parseTableQualifiedNameNegative(name, errorMsg, "only white spaces in string");
+    }
+
+    private String surroundByQuotes(String str) {
+        return "\"" + str + "\"";
+    }
+
+    private void parseTableQualifiedNameNegative(String name, String errorMsg, String reason) throws Exception {
+        try {
+            tblDesc = HiveUtilities.parseTableQualifiedName(name);
+            fail("test should fail because of " + reason);
+        } catch (IllegalArgumentException e) {
+            assertEquals(errorMsg, e.getMessage());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/AnalyzerFactory.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/AnalyzerFactory.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/AnalyzerFactory.java
deleted file mode 100644
index 28fba29..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/AnalyzerFactory.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.pivotal.pxf.service;
-
-import com.pivotal.pxf.api.Analyzer;
-import com.pivotal.pxf.api.utilities.InputData;
-import com.pivotal.pxf.service.utilities.Utilities;
-
-/*
- * Factory class for creation of Analyzer objects. The actual Analyzer object is "hidden" behind
- * an Analyzer abstract class which is returned by the AnalyzerFactory. 
- */
-public class AnalyzerFactory {
-    static public Analyzer create(InputData inputData) throws Exception {
-    	String analyzerName = inputData.getAnalyzer();
-    	
-        return (Analyzer) Utilities.createAnyInstance(InputData.class, analyzerName, inputData);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/Bridge.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/Bridge.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/Bridge.java
deleted file mode 100644
index a02060b..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/Bridge.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.pivotal.pxf.service;
-
-import com.pivotal.pxf.service.io.Writable;
-
-import java.io.DataInputStream;
-
-/*
- * Bridge interface - defines the interface of the Bridge classes.
- * Any Bridge class acts as an iterator over Hadoop stored data, and 
- * should implement getNext (for reading) or setNext (for writing) 
- * for handling accessed data.
- */
-public interface Bridge {
-    boolean beginIteration() throws Exception;
-
-    Writable getNext() throws Exception;
-
-    boolean setNext(DataInputStream inputStream) throws Exception;
-
-    boolean isThreadSafe();
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/BridgeInputBuilder.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/BridgeInputBuilder.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/BridgeInputBuilder.java
deleted file mode 100644
index 33f90be..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/BridgeInputBuilder.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.pivotal.pxf.service;
-
-import com.pivotal.pxf.api.OneField;
-import com.pivotal.pxf.api.OutputFormat;
-import com.pivotal.pxf.api.io.DataType;
-import com.pivotal.pxf.service.io.GPDBWritable;
-import com.pivotal.pxf.service.io.Text;
-import com.pivotal.pxf.service.utilities.ProtocolData;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.DataInput;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-public class BridgeInputBuilder {
-    private ProtocolData protocolData;
-    private static final Log LOG = LogFactory.getLog(BridgeInputBuilder.class);
-
-    public BridgeInputBuilder(ProtocolData protocolData) throws Exception {
-        this.protocolData = protocolData;
-    }
-
-    public List<OneField> makeInput(DataInput inputStream) throws Exception {
-        if (protocolData.outputFormat() == OutputFormat.TEXT) {
-            Text txt = new Text();
-            txt.readFields(inputStream);
-            return Collections.singletonList(new OneField(DataType.BYTEA.getOID(), txt.getBytes()));
-        }
-
-        GPDBWritable gpdbWritable = new GPDBWritable();
-        gpdbWritable.readFields(inputStream);
-
-        if (gpdbWritable.isEmpty()) {
-            LOG.debug("Reached end of stream");
-            return null;
-        }
-
-        GPDBWritableMapper mapper = new GPDBWritableMapper(gpdbWritable);
-        int[] colTypes = gpdbWritable.getColType();
-        List<OneField> record = new LinkedList<OneField>();
-        for (int i = 0; i < colTypes.length; i++) {
-            mapper.setDataType(colTypes[i]);
-            record.add(new OneField(colTypes[i], mapper.getData(i)));
-        }
-
-        return record;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/BridgeOutputBuilder.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/BridgeOutputBuilder.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/BridgeOutputBuilder.java
deleted file mode 100644
index dd8111b..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/BridgeOutputBuilder.java
+++ /dev/null
@@ -1,288 +0,0 @@
-package com.pivotal.pxf.service;
-
-import com.pivotal.pxf.api.BadRecordException;
-import com.pivotal.pxf.api.OneField;
-import com.pivotal.pxf.api.OutputFormat;
-import com.pivotal.pxf.api.io.DataType;
-import com.pivotal.pxf.service.io.BufferWritable;
-import com.pivotal.pxf.service.io.GPDBWritable;
-import com.pivotal.pxf.service.io.GPDBWritable.TypeMismatchException;
-import com.pivotal.pxf.service.io.Text;
-import com.pivotal.pxf.service.io.Writable;
-import com.pivotal.pxf.service.utilities.ProtocolData;
-import org.apache.commons.lang.ObjectUtils;
-
-import java.lang.reflect.Array;
-import java.util.Arrays;
-import java.util.List;
-
-import static com.pivotal.pxf.api.io.DataType.TEXT;
-
-/**
- * Class creates the output record that is piped by the java process to the HAWQ
- * backend. Actually, the output record is serialized and the obtained byte
- * string is piped to the HAWQ segment. The output record will implement
- * Writable, and the mission of BridgeOutputBuilder will be to translate a list
- * of {@link OneField} objects (obtained from the Resolver) into an output
- * record.
- */
-public class BridgeOutputBuilder {
-    private ProtocolData inputData;
-    private Writable output = null;
-    private GPDBWritable errorRecord = null;
-    private int[] schema;
-    private String[] colNames;
-
-    /**
-     * Constructs a BridgeOutputBuilder.
-     *
-     * @param input input data, like requested output format and schema
-     *            information
-     */
-    public BridgeOutputBuilder(ProtocolData input) {
-        inputData = input;
-        makeErrorRecord();
-    }
-
-    /**
-     * We need a separate GPDBWritable record to represent the error record.
-     * Just setting the errorFlag on the "output" GPDBWritable variable is not
-     * good enough, since the GPDBWritable is built only after the first record
-     * is read from the file. And if we encounter an error while fetching the
-     * first record from the file, then the output member will be null. The
-     * reason we cannot count on the schema to build the GPDBWritable output
-     * variable before reading the first record, is because the schema does not
-     * account for arrays - we cannot know from the schema the length of an
-     * array. We find out only after fetching the first record.
-     */
-    void makeErrorRecord() {
-        int[] errSchema = { TEXT.getOID() };
-
-        if (inputData.outputFormat() != OutputFormat.BINARY) {
-            return;
-        }
-
-        errorRecord = new GPDBWritable(errSchema);
-        errorRecord.setError(true);
-    }
-
-    /**
-     * Returns the error record. If the output format is not binary, error
-     * records are not supported, and the given exception will be thrown
-     *
-     * @param ex exception to be stored in record
-     * @return error record
-     * @throws Exception if the output format is not binary
-     */
-    public Writable getErrorOutput(Exception ex) throws Exception {
-        if (inputData.outputFormat() == OutputFormat.BINARY) {
-            errorRecord.setString(0, ex.getMessage());
-            return errorRecord;
-        } else {
-            throw ex;
-        }
-    }
-
-    /**
-     * Translates recFields (obtained from the Resolver) into an output record.
-     *
-     * @param recFields record fields to be serialized
-     * @return Writable object with serialized row
-     * @throws BadRecordException if building the output record failed
-     */
-    public Writable makeOutput(List<OneField> recFields)
-            throws BadRecordException {
-        if (output == null && inputData.outputFormat() == OutputFormat.BINARY) {
-            makeGPDBWritableOutput();
-        }
-
-        fillOutputRecord(recFields);
-
-        return output;
-    }
-
-    /**
-     * Creates the GPDBWritable object. The object is created one time and is
-     * refilled from recFields for each record sent
-     *
-     * @return empty GPDBWritable object with set columns
-     */
-    GPDBWritable makeGPDBWritableOutput() {
-        int num_actual_fields = inputData.getColumns();
-        schema = new int[num_actual_fields];
-        colNames = new String[num_actual_fields];
-
-        for (int i = 0; i < num_actual_fields; i++) {
-            schema[i] = inputData.getColumn(i).columnTypeCode();
-            colNames[i] = inputData.getColumn(i).columnName();
-        }
-
-        output = new GPDBWritable(schema);
-
-        return (GPDBWritable) output;
-    }
-
-    /**
-     * Fills the output record based on the fields in recFields.
-     *
-     * @param recFields record fields
-     * @throws BadRecordException if building the output record failed
-     */
-    void fillOutputRecord(List<OneField> recFields) throws BadRecordException {
-        if (inputData.outputFormat() == OutputFormat.BINARY) {
-            fillGPDBWritable(recFields);
-        } else {
-            fillText(recFields);
-        }
-    }
-
-    /**
-     * Fills a GPDBWritable object based on recFields. The input record
-     * recFields must correspond to schema. If the record has more or less
-     * fields than the schema we throw an exception. We require that the type of
-     * field[i] in recFields corresponds to the type of field[i] in the schema.
-     *
-     * @param recFields record fields
-     * @throws BadRecordException if building the output record failed
-     */
-    void fillGPDBWritable(List<OneField> recFields) throws BadRecordException {
-        int size = recFields.size();
-        if (size == 0) { // size 0 means the resolver couldn't deserialize any
-                         // of the record fields
-            throw new BadRecordException("No fields in record");
-        } else if (size != schema.length) {
-            throw new BadRecordException("Record has " + size
-                    + " fields but the schema size is " + schema.length);
-        }
-
-        for (int i = 0; i < size; i++) {
-            OneField current = recFields.get(i);
-            if (!isTypeInSchema(current.type, schema[i])) {
-                throw new BadRecordException("For field " + colNames[i]
-                        + " schema requires type "
-                        + DataType.get(schema[i]).toString()
-                        + " but input record has type "
-                        + DataType.get(current.type).toString());
-            }
-
-            fillOneGPDBWritableField(current, i);
-        }
-    }
-
-    /**
-     * Tests if data type is a string type. String type is a type that can be
-     * serialized as string, such as varchar, bpchar, text, numeric, timestamp,
-     * date.
-     *
-     * @param type data type
-     * @return whether data type is string type
-     */
-    boolean isStringType(DataType type) {
-        return Arrays.asList(DataType.VARCHAR, DataType.BPCHAR, DataType.TEXT,
-                DataType.NUMERIC, DataType.TIMESTAMP, DataType.DATE).contains(
-                type);
-    }
-
-    /**
-     * Tests if record field type and schema type correspond.
-     *
-     * @param recType record type code
-     * @param schemaType schema type code
-     * @return whether record type and schema type match
-     */
-    boolean isTypeInSchema(int recType, int schemaType) {
-        DataType dtRec = DataType.get(recType);
-        DataType dtSchema = DataType.get(schemaType);
-
-        return (dtSchema == DataType.UNSUPPORTED_TYPE || dtRec == dtSchema || (isStringType(dtRec) && isStringType(dtSchema)));
-    }
-
-    /**
-     * Fills a Text object based on recFields.
-     *
-     * @param recFields record fields
-     * @throws BadRecordException if text formatted record has more than one field
-     */
-    void fillText(List<OneField> recFields) throws BadRecordException {
-        /*
-         * For the TEXT case there must be only one record in the list
-         */
-        if (recFields.size() != 1) {
-            throw new BadRecordException(
-                    "BridgeOutputBuilder must receive one field when handling the TEXT format");
-        }
-
-        OneField fld = recFields.get(0);
-        int type = fld.type;
-        Object val = fld.val;
-        if (DataType.get(type) == DataType.BYTEA) {// from LineBreakAccessor
-            output = new BufferWritable((byte[]) val);
-        } else { // from QuotedLineBreakAccessor
-            String textRec = (String) val;
-            output = new Text(textRec + "\n");
-        }
-    }
-
-    /**
-     * Fills one GPDBWritable field.
-     *
-     * @param oneField field
-     * @param colIdx column index
-     * @throws BadRecordException if field type is not supported or doesn't match the schema
-     */
-    void fillOneGPDBWritableField(OneField oneField, int colIdx)
-            throws BadRecordException {
-        int type = oneField.type;
-        Object val = oneField.val;
-        GPDBWritable GPDBoutput = (GPDBWritable) output;
-        try {
-            switch (DataType.get(type)) {
-                case INTEGER:
-                    GPDBoutput.setInt(colIdx, (Integer) val);
-                    break;
-                case FLOAT8:
-                    GPDBoutput.setDouble(colIdx, (Double) val);
-                    break;
-                case REAL:
-                    GPDBoutput.setFloat(colIdx, (Float) val);
-                    break;
-                case BIGINT:
-                    GPDBoutput.setLong(colIdx, (Long) val);
-                    break;
-                case SMALLINT:
-                    GPDBoutput.setShort(colIdx, (Short) val);
-                    break;
-                case BOOLEAN:
-                    GPDBoutput.setBoolean(colIdx, (Boolean) val);
-                    break;
-                case BYTEA:
-                    byte[] bts = null;
-                    if (val != null) {
-                        int length = Array.getLength(val);
-                        bts = new byte[length];
-                        for (int j = 0; j < length; j++) {
-                            bts[j] = Array.getByte(val, j);
-                        }
-                    }
-                    GPDBoutput.setBytes(colIdx, bts);
-                    break;
-                case VARCHAR:
-                case BPCHAR:
-                case CHAR:
-                case TEXT:
-                case NUMERIC:
-                case TIMESTAMP:
-                case DATE:
-                    GPDBoutput.setString(colIdx, ObjectUtils.toString(val, null));
-                    break;
-                default:
-                    String valClassName = (val != null) ? val.getClass().getSimpleName()
-                            : null;
-                    throw new UnsupportedOperationException(valClassName
-                            + " is not supported for HAWQ conversion");
-            }
-        } catch (TypeMismatchException e) {
-            throw new BadRecordException(e);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmenterFactory.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmenterFactory.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmenterFactory.java
deleted file mode 100644
index 2b6211d..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmenterFactory.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.pivotal.pxf.service;
-
-import com.pivotal.pxf.api.Fragmenter;
-import com.pivotal.pxf.api.utilities.InputData;
-import com.pivotal.pxf.service.utilities.Utilities;
-
-/**
- * Factory class for creation of {@link Fragmenter} objects. The actual {@link Fragmenter} object is "hidden" behind
- * an {@link Fragmenter} abstract class which is returned by the FragmenterFactory. 
- */
-public class FragmenterFactory {
-    static public Fragmenter create(InputData inputData) throws Exception {
-    	String fragmenterName = inputData.getFragmenter();
-    	
-        return (Fragmenter) Utilities.createAnyInstance(InputData.class, fragmenterName, inputData);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmentsResponse.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmentsResponse.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmentsResponse.java
deleted file mode 100644
index 87e918b..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmentsResponse.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.pivotal.pxf.service;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.List;
-
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.StreamingOutput;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codehaus.jackson.map.ObjectMapper;
-
-import com.pivotal.pxf.api.Fragment;
-
-/**
- * Class for serializing fragments metadata in JSON format.
- * The class implements {@link StreamingOutput} so the serialization will be
- * done in a stream and not in one bulk, this in order to avoid running
- * out of memory when processing a lot of fragments.
- */
-public class FragmentsResponse implements StreamingOutput {
-
-    private static Log Log = LogFactory.getLog(FragmentsResponse.class);
-
-    private List<Fragment> fragments;
-
-    /**
-     * Constructs fragments response out of a list of fragments
-     *
-     * @param fragments fragment list
-     */
-    public FragmentsResponse(List<Fragment> fragments) {
-        this.fragments = fragments;
-    }
-
-    /**
-     * Serializes a fragments list in JSON,
-     * To be used as the result string for HAWQ.
-     * An example result is as follows:
-     * {@code {"PXFFragments":[{"replicas":["sdw1.corp.emc.com","sdw3.corp.emc.com","sdw8.corp.emc.com"],"sourceName":"text2.csv", "index":"0", "metadata":<base64 metadata for fragment>, "userData":"<data_specific_to_third_party_fragmenter>"},{"replicas":["sdw2.corp.emc.com","sdw4.corp.emc.com","sdw5.corp.emc.com"],"sourceName":"text_data.csv","index":"0","metadata":<base64 metadata for fragment>,"userData":"<data_specific_to_third_party_fragmenter>"}]}}
-     */
-    @Override
-    public void write(OutputStream output) throws IOException,
-            WebApplicationException {
-        DataOutputStream dos = new DataOutputStream(output);
-        ObjectMapper mapper = new ObjectMapper();
-
-        dos.write("{\"PXFFragments\":[".getBytes());
-
-        String prefix = "";
-        for (Fragment fragment : fragments) {
-            StringBuilder result = new StringBuilder();
-            /* metaData and userData are automatically converted to Base64 */
-            result.append(prefix).append(mapper.writeValueAsString(fragment));
-            prefix = ",";
-            dos.write(result.toString().getBytes());
-        }
-
-        dos.write("]}".getBytes());
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmentsResponseFormatter.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmentsResponseFormatter.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmentsResponseFormatter.java
deleted file mode 100644
index 5145929..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/FragmentsResponseFormatter.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package com.pivotal.pxf.service;
-
-import com.pivotal.pxf.api.Fragment;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.HashMap;
-import java.util.List;
-
-/**
- * Utility class for converting Fragments into a {@link FragmentsResponse}
- * that will serialize them into JSON format.
- */
-public class FragmentsResponseFormatter {
-
-    private static Log LOG = LogFactory.getLog(FragmentsResponseFormatter.class);
-
-    /**
-     * Converts Fragments list to FragmentsResponse
-     * after replacing host name by their respective IPs.
-     *
-     * @param fragments list of fragments
-     * @param data data (e.g. path) related to the fragments
-     * @return FragmentsResponse with given fragments
-     * @throws UnknownHostException if converting host names to IP fails
-     */
-    public static FragmentsResponse formatResponse(List<Fragment> fragments, String data) throws UnknownHostException   {
-        /* print the raw fragment list to log when in debug level */
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Fragments before conversion to IP list:");
-            FragmentsResponseFormatter.printList(fragments, data);
-        }
-
-        /* HD-2550: convert host names to IPs */
-        convertHostsToIPs(fragments);
-
-        updateFragmentIndex(fragments);
-
-	/* print the fragment list to log when in debug level */
-        if (LOG.isDebugEnabled()) {
-            FragmentsResponseFormatter.printList(fragments, data);
-        }
-
-        return new FragmentsResponse(fragments);
-    }
-
-    /**
-     * Updates the fragments' indexes so that it is incremented by sourceName.
-     * (E.g.: {"a", 0}, {"a", 1}, {"b", 0} ... )
-     *
-     * @param fragments fragments to be updated
-     */
-    private static void updateFragmentIndex(List<Fragment> fragments) {
-
-        String sourceName = null;
-        int index = 0;
-        for (Fragment fragment : fragments) {
-
-            String currentSourceName = fragment.getSourceName();
-            if (!currentSourceName.equals(sourceName)) {
-                index = 0;
-                sourceName = currentSourceName;
-            }
-            fragment.setIndex(index++);
-        }
-    }
-
-    /**
-     * Converts hosts to their matching IP addresses.
-     *
-     * @throws UnknownHostException if converting host name to IP fails
-     */
-    private static void convertHostsToIPs(List<Fragment> fragments) throws UnknownHostException {
-        /* host converted to IP map. Used to limit network calls. */
-        HashMap<String, String> hostToIpMap = new HashMap<String, String>();
-
-        for (Fragment fragment : fragments) {
-            String[] hosts = fragment.getReplicas();
-            if (hosts == null) {
-                continue;
-            }
-            String[] ips = new String[hosts.length];
-            int index = 0;
-
-            for (String host : hosts) {
-                String convertedIp = hostToIpMap.get(host);
-                if (convertedIp == null) {
-                    /* find host's IP, and add to map */
-                    InetAddress addr = InetAddress.getByName(host);
-                    convertedIp = addr.getHostAddress();
-                    hostToIpMap.put(host, convertedIp);
-                }
-
-                /* update IPs array */
-                ips[index] = convertedIp;
-                ++index;
-            }
-            fragment.setReplicas(ips);
-        }
-    }
-
-    /*
-     * Converts a fragments list to a readable string and prints it to the log.
-     * Intended for debugging purposes only.
-     * 'datapath' is the data path part of the original URI (e.g., table name, *.csv, etc).
-	 */
-    private static void printList(List<Fragment> fragments, String datapath) {
-        LOG.debug("List of " +
-                (fragments.isEmpty() ? "no" : fragments.size()) + "fragments for \"" +
-                 datapath + "\"");
-
-        int i = 0;
-        for (Fragment fragment : fragments) {
-            StringBuilder result = new StringBuilder();
-            result.append("Fragment #").append(++i).append(": [")
-                .append("Source: ").append(fragment.getSourceName())
-                .append(", Index: ").append(fragment.getIndex())
-                .append(", Replicas:");
-            for (String host : fragment.getReplicas()) {
-                result.append(" ").append(host);
-            }
-
-            result.append(", Metadata: ").append(new String(fragment.getMetadata()));
-
-            if (fragment.getUserData() != null) {
-                result.append(", User Data: ").append(new String(fragment.getUserData()));
-            }
-            result.append("] ");
-            LOG.debug(result);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/GPDBWritableMapper.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/GPDBWritableMapper.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/GPDBWritableMapper.java
deleted file mode 100644
index cfed326..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/GPDBWritableMapper.java
+++ /dev/null
@@ -1,115 +0,0 @@
-package com.pivotal.pxf.service;
-
-import com.pivotal.pxf.api.UnsupportedTypeException;
-import com.pivotal.pxf.api.io.DataType;
-import com.pivotal.pxf.service.io.GPDBWritable;
-import com.pivotal.pxf.service.io.GPDBWritable.TypeMismatchException;
-
-/*
- * Class for mapping GPDBWritable get functions to java types.
- */
-public class GPDBWritableMapper {
-
-    private GPDBWritable gpdbWritable;
-    private int type;
-    private DataGetter getter = null;
-
-    public GPDBWritableMapper(GPDBWritable gpdbWritable) {
-        this.gpdbWritable = gpdbWritable;
-    }
-
-    public void setDataType(int type) throws UnsupportedTypeException {
-        this.type = type;
-
-        switch (DataType.get(type)) {
-            case BOOLEAN:
-                getter = new BooleanDataGetter();
-                break;
-            case BYTEA:
-                getter = new BytesDataGetter();
-                break;
-            case BIGINT:
-                getter = new LongDataGetter();
-                break;
-            case SMALLINT:
-                getter = new ShortDataGetter();
-                break;
-            case INTEGER:
-                getter = new IntDataGetter();
-                break;
-            case TEXT:
-                getter = new StringDataGetter();
-                break;
-            case REAL:
-                getter = new FloatDataGetter();
-                break;
-            case FLOAT8:
-                getter = new DoubleDataGetter();
-                break;
-            default:
-                throw new UnsupportedTypeException(
-                        "Type " + GPDBWritable.getTypeName(type) +
-                                " is not supported by GPDBWritable");
-        }
-    }
-
-    public Object getData(int colIdx) throws TypeMismatchException {
-        return getter.getData(colIdx);
-    }
-
-    private interface DataGetter {
-        abstract Object getData(int colIdx) throws TypeMismatchException;
-    }
-
-    private class BooleanDataGetter implements DataGetter {
-        public Object getData(int colIdx) throws TypeMismatchException {
-            return gpdbWritable.getBoolean(colIdx);
-        }
-    }
-
-    private class BytesDataGetter implements DataGetter {
-        public Object getData(int colIdx) throws TypeMismatchException {
-            return gpdbWritable.getBytes(colIdx);
-        }
-    }
-
-    private class DoubleDataGetter implements DataGetter {
-        public Object getData(int colIdx) throws TypeMismatchException {
-            return gpdbWritable.getDouble(colIdx);
-        }
-    }
-
-    private class FloatDataGetter implements DataGetter {
-        public Object getData(int colIdx) throws TypeMismatchException {
-            return gpdbWritable.getFloat(colIdx);
-        }
-    }
-
-    private class IntDataGetter implements DataGetter {
-        public Object getData(int colIdx) throws TypeMismatchException {
-            return gpdbWritable.getInt(colIdx);
-        }
-    }
-
-    private class LongDataGetter implements DataGetter {
-        public Object getData(int colIdx) throws TypeMismatchException {
-            return gpdbWritable.getLong(colIdx);
-        }
-    }
-
-    private class ShortDataGetter implements DataGetter {
-        public Object getData(int colIdx) throws TypeMismatchException {
-            return gpdbWritable.getShort(colIdx);
-        }
-    }
-
-    private class StringDataGetter implements DataGetter {
-        public Object getData(int colIdx) throws TypeMismatchException {
-            return gpdbWritable.getString(colIdx);
-        }
-    }
-
-    public String toString() {
-        return "getter type = " + GPDBWritable.getTypeName(type);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/MetadataFetcherFactory.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/MetadataFetcherFactory.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/MetadataFetcherFactory.java
deleted file mode 100644
index c76a89a..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/MetadataFetcherFactory.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.pivotal.pxf.service;
-
-import com.pivotal.pxf.api.MetadataFetcher;
-
-/**
- * Factory class for creation of {@link MetadataFetcher} objects. 
- * The actual {@link MetadataFetcher} object is "hidden" behind an {@link MetadataFetcher} 
- * abstract class which is returned by the MetadataFetcherFactory. 
- */
-public class MetadataFetcherFactory {
-    static public MetadataFetcher create(String fetcherName) throws Exception {
-        return (MetadataFetcher) Class.forName(fetcherName).newInstance();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/MetadataResponseFormatter.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/MetadataResponseFormatter.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/MetadataResponseFormatter.java
deleted file mode 100644
index 1bb0cfd..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/MetadataResponseFormatter.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package com.pivotal.pxf.service;
-
-import java.io.IOException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
-
-import com.pivotal.pxf.api.Metadata;
-
-/**
- * Utility class for converting {@link Metadata} into a JSON format.
- */
-public class MetadataResponseFormatter {
-
-    private static Log Log = LogFactory.getLog(MetadataResponseFormatter.class);
-
-    /**
-     * Converts {@link Metadata} to JSON String format.
-     *
-     * @param metadata metadata to convert
-     * @return JSON formatted response
-     * @throws IOException if converting the data to JSON fails
-     */
-    public static String formatResponseString(Metadata metadata) throws IOException {
-        /* print the metadata before serialization */
-        Log.debug(MetadataResponseFormatter.metadataToString(metadata));
-
-        return MetadataResponseFormatter.metadataToJSON(metadata);
-    }
-
-    /**
-     * Serializes a metadata in JSON,
-     * To be used as the result string for HAWQ.
-     * An example result is as follows:
-     *
-     * {"PXFMetadata":[{"table":{"dbName":"default","tableName":"t1"},"fields":[{"name":"a","type":"int"},{"name":"b","type":"float"}]}]}
-     */
-    private static String metadataToJSON(Metadata metadata) throws IOException {
-
-        if (metadata == null) {
-            throw new IllegalArgumentException("metadata object is null - cannot serialize");
-        }
-
-        if ((metadata.getFields() == null) || metadata.getFields().isEmpty()) {
-            throw new IllegalArgumentException("metadata contains no fields - cannot serialize");
-        }
-
-        ObjectMapper mapper = new ObjectMapper();
-        mapper.setSerializationInclusion(Inclusion.NON_EMPTY); // ignore empty fields
-
-        StringBuilder result = new StringBuilder("{\"PXFMetadata\":");
-        String prefix = "["; // preparation for supporting multiple tables
-        result.append(prefix).append(mapper.writeValueAsString(metadata));
-        return result.append("]}").toString();
-    }
-
-    /**
-     * Converts metadata to a readable string.
-     * Intended for debugging purposes only.
-     */
-    private static String metadataToString(Metadata metadata) {
-        StringBuilder result = new StringBuilder("Metadata for table \"");
-
-        if (metadata == null) {
-            return "No metadata";
-        }
-
-        result.append(metadata.getTable()).append("\": ");
-
-        if ((metadata.getFields() == null) || metadata.getFields().isEmpty()) {
-            result.append("no fields in table");
-            return result.toString();
-        }
-
-        int i = 0;
-        for (Metadata.Field field: metadata.getFields()) {
-            result.append("Field #").append(++i).append(": [")
-                .append("Name: ").append(field.getName())
-                .append(", Type: ").append(field.getType()).append("] ");
-        }
-
-        return result.toString();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/ReadBridge.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/ReadBridge.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/ReadBridge.java
deleted file mode 100644
index f33972c..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/ReadBridge.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package com.pivotal.pxf.service;
-
-import com.pivotal.pxf.api.BadRecordException;
-import com.pivotal.pxf.api.OneRow;
-import com.pivotal.pxf.api.ReadAccessor;
-import com.pivotal.pxf.api.ReadResolver;
-import com.pivotal.pxf.api.utilities.InputData;
-import com.pivotal.pxf.api.utilities.Plugin;
-import com.pivotal.pxf.service.io.Writable;
-import com.pivotal.pxf.service.utilities.ProtocolData;
-import com.pivotal.pxf.service.utilities.Utilities;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.*;
-import java.nio.charset.CharacterCodingException;
-import java.util.zip.ZipException;
-
-/*
- * ReadBridge class creates appropriate accessor and resolver.
- * It will then create the correct output conversion
- * class (e.g. Text or GPDBWritable) and get records from accessor,
- * let resolver deserialize them and reserialize them using the
- * output conversion class.
- *
- * The class handles BadRecordException and other exception type
- * and marks the record as invalid for GPDB.
- */
-public class ReadBridge implements Bridge {
-    ReadAccessor fileAccessor = null;
-    ReadResolver fieldsResolver = null;
-    BridgeOutputBuilder outputBuilder = null;
-
-    private Log Log;
-
-    /*
-     * C'tor - set the implementation of the bridge
-     */
-    public ReadBridge(ProtocolData protData) throws Exception {
-        outputBuilder = new BridgeOutputBuilder(protData);
-        Log = LogFactory.getLog(ReadBridge.class);
-        fileAccessor = getFileAccessor(protData);
-        fieldsResolver = getFieldsResolver(protData);
-    }
-
-    /*
-     * Accesses the underlying HDFS file
-     */
-    @Override
-    public boolean beginIteration() throws Exception {
-        return fileAccessor.openForRead();
-    }
-
-    /*
-     * Fetch next object from file and turn it into a record that the GPDB backend can process
-     */
-    @Override
-    public Writable getNext() throws Exception {
-        Writable output;
-        OneRow onerow = null;
-        try {
-            onerow = fileAccessor.readNextObject();
-            if (onerow == null) {
-                fileAccessor.closeForRead();
-                return null;
-            }
-
-            output = outputBuilder.makeOutput(fieldsResolver.getFields(onerow));
-        } catch (IOException ex) {
-            if (!isDataException(ex)) {
-                fileAccessor.closeForRead();
-                throw ex;
-            }
-            output = outputBuilder.getErrorOutput(ex);
-        } catch (BadRecordException ex) {
-            String row_info = "null";
-            if (onerow != null) {
-                row_info = onerow.toString();
-            }
-            if (ex.getCause() != null) {
-                Log.debug("BadRecordException " + ex.getCause().toString() + ": " + row_info);
-            } else {
-                Log.debug(ex.toString() + ": " + row_info);
-            }
-            output = outputBuilder.getErrorOutput(ex);
-        } catch (Exception ex) {
-            fileAccessor.closeForRead();
-            throw ex;
-        }
-
-        return output;
-    }
-
-    public static ReadAccessor getFileAccessor(InputData inputData) throws Exception {
-        return (ReadAccessor) Utilities.createAnyInstance(InputData.class, inputData.getAccessor(), inputData);
-    }
-
-    public static ReadResolver getFieldsResolver(InputData inputData) throws Exception {
-        return (ReadResolver) Utilities.createAnyInstance(InputData.class, inputData.getResolver(), inputData);
-    }
-
-    /*
-     * There are many exceptions that inherit IOException. Some of them like EOFException are generated
-     * due to a data problem, and not because of an IO/connection problem as the father IOException
-     * might lead us to believe. For example, an EOFException will be thrown while fetching a record
-     * from a sequence file, if there is a formatting problem in the record. Fetching record from
-     * the sequence-file is the responsibility of the accessor so the exception will be thrown from the
-     * accessor. We identify this cases by analyzing the exception type, and when we discover that the
-     * actual problem was a data problem, we return the errorOutput GPDBWritable.
-     */
-    private boolean isDataException(IOException ex) {
-        return (ex instanceof EOFException || ex instanceof CharacterCodingException ||
-                ex instanceof CharConversionException || ex instanceof UTFDataFormatException ||
-                ex instanceof ZipException);
-    }
-
-    @Override
-    public boolean setNext(DataInputStream inputStream) {
-        throw new UnsupportedOperationException("setNext is not implemented");
-    }
-
-    @Override
-    public boolean isThreadSafe() {
-        boolean result = ((Plugin) fileAccessor).isThreadSafe() && ((Plugin) fieldsResolver).isThreadSafe();
-        Log.debug("Bridge is " + (result ? "" : "not ") + "thread safe");
-        return result;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/WriteBridge.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/WriteBridge.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/WriteBridge.java
deleted file mode 100644
index a9286d0..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/WriteBridge.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package com.pivotal.pxf.service;
-
-import com.pivotal.pxf.api.*;
-import com.pivotal.pxf.api.utilities.InputData;
-import com.pivotal.pxf.api.utilities.Plugin;
-import com.pivotal.pxf.service.io.Writable;
-import com.pivotal.pxf.service.utilities.ProtocolData;
-import com.pivotal.pxf.service.utilities.Utilities;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.DataInputStream;
-import java.util.List;
-
-/*
- * WriteBridge class creates appropriate accessor and resolver.
- * It reads data from inputStream by the resolver,
- * and writes it to the Hadoop storage with the accessor.
- */
-public class WriteBridge implements Bridge {
-    private static final Log LOG = LogFactory.getLog(WriteBridge.class);
-    WriteAccessor fileAccessor = null;
-    WriteResolver fieldsResolver = null;
-    BridgeInputBuilder inputBuilder;
-
-    /*
-     * C'tor - set the implementation of the bridge
-     */
-    public WriteBridge(ProtocolData protocolData) throws Exception {
-    	
-        inputBuilder = new BridgeInputBuilder(protocolData);        
-        /* plugins accept InputData paramaters */
-        fileAccessor = getFileAccessor(protocolData);
-        fieldsResolver = getFieldsResolver(protocolData);
-        
-    }
-
-    /*
-     * Accesses the underlying HDFS file
-     */
-    public boolean beginIteration() throws Exception {
-        return fileAccessor.openForWrite();
-    }
-
-    /*
-     * Read data from stream, convert it using WriteResolver into OneRow object, and
-     * pass to WriteAccessor to write into file.
-     */
-    @Override
-    public boolean setNext(DataInputStream inputStream) throws Exception {
-
-        List<OneField> record = inputBuilder.makeInput(inputStream);
-        if (record == null) {
-            close();
-            return false;
-        }
-
-        OneRow onerow = fieldsResolver.setFields(record);
-        if (onerow == null) {
-            close();
-            return false;
-        }
-        if (!fileAccessor.writeNextObject(onerow)) {
-            close();
-            throw new BadRecordException();
-        }
-        return true;
-    }
-
-    private void close() throws Exception {
-        try {
-            fileAccessor.closeForWrite();
-        } catch (Exception e) {
-            LOG.error("Failed to close bridge resources: " + e.getMessage());
-            throw e;
-        }
-    }
-
-    private static WriteAccessor getFileAccessor(InputData inputData) throws Exception {
-        return (WriteAccessor) Utilities.createAnyInstance(InputData.class, inputData.getAccessor(), inputData);
-    }
-
-    private static WriteResolver getFieldsResolver(InputData inputData) throws Exception {
-        return (WriteResolver) Utilities.createAnyInstance(InputData.class, inputData.getResolver(), inputData);
-    }
-
-    @Override
-    public Writable getNext() {
-        throw new UnsupportedOperationException("getNext is not implemented");
-    }
-
-    @Override
-    public boolean isThreadSafe() {
-        return ((Plugin) fileAccessor).isThreadSafe() && ((Plugin) fieldsResolver).isThreadSafe();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/io/BufferWritable.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/io/BufferWritable.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/io/BufferWritable.java
deleted file mode 100644
index 3115ca7..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/io/BufferWritable.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.pivotal.pxf.service.io;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.lang.UnsupportedOperationException;
-
-/**
- * A serializable object for transporting a byte array through the Bridge
- * framework
- */
-public class BufferWritable implements Writable {
-
-    byte[] buf = null;
-
-    /**
-     * Constructs a BufferWritable. Copies the buffer reference and not the
-     * actual bytes. This class is used when we intend to transport a buffer
-     * through the Bridge framework without copying the data each time the
-     * buffer is passed between the Bridge objects.
-     *
-     * @param inBuf buffer
-     */
-    public BufferWritable(byte[] inBuf) {
-        buf = inBuf;
-    }
-
-    /**
-     * Serializes the fields of this object to <code>out</code>.
-     *
-     * @param out <code>DataOutput</code> to serialize this object into.
-     * @throws IOException if the buffer was not set
-     */
-    @Override
-    public void write(DataOutput out) throws IOException {
-        if (buf == null)
-            throw new IOException("BufferWritable was not set");
-        out.write(buf);
-    }
-
-    /**
-     * Deserializes the fields of this object from <code>in</code>.
-     * <p>
-     * For efficiency, implementations should attempt to re-use storage in the
-     * existing object where possible.
-     * </p>
-     *
-     * @param in <code>DataInput</code> to deserialize this object from
-     * @throws UnsupportedOperationException this function is not supported
-     */
-    @Override
-    public void readFields(DataInput in) {
-        throw new UnsupportedOperationException(
-                "BufferWritable.readFields() is not implemented");
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f053e053/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/io/GPDBWritable.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/io/GPDBWritable.java b/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/io/GPDBWritable.java
deleted file mode 100644
index 074f97e..0000000
--- a/pxf/pxf-service/src/main/java/com/pivotal/pxf/service/io/GPDBWritable.java
+++ /dev/null
@@ -1,873 +0,0 @@
-package com.pivotal.pxf.service.io;
-
-import com.pivotal.pxf.api.io.DataType;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.*;
-import java.util.Arrays;
-
-import static com.pivotal.pxf.api.io.DataType.*;
-
-
-/**
- * This class represents a GPDB record in the form of
- * a Java object.
- */
-public class GPDBWritable implements Writable {
-    /*
-     * GPDBWritable is using the following serialization form:
-	 * Total Length | Version | Error Flag | # of columns | Col type |...| Col type | Null Bit array            |   Col val...
-     * 4 byte		| 2 byte  |	1 byte     |   2 byte     |  1 byte  |...|  1 byte  | ceil(# of columns/8) byte |   Fixed or Var length
-     *
-     * For fixed length type, we know the length.
-     * In the col val, we align pad according to the alignment requirement of the type.
-     * For var length type, the alignment is always 4 byte.
-     * For var length type, col val is <4 byte length><payload val>
-	 */
-
-    private static Log Log = LogFactory.getLog(GPDBWritable.class);
-    private static final int EOF = -1;
-
-    /*
-     * Enum of the Database type
-     */
-    private enum DBType {
-        BIGINT(8, 8),
-        BOOLEAN(1, 1),
-        FLOAT8(8, 8),
-        INTEGER(4, 4),
-        REAL(4, 4),
-        SMALLINT(2, 2),
-        BYTEA(4, -1),
-        TEXT(4, -1);
-
-        private final int typelength; // -1 means var length
-        private final int alignment;
-
-        DBType(int align, int len) {
-            this.typelength = len;
-            this.alignment = align;
-        }
-
-        public int getTypeLength() {
-            return typelength;
-        }
-
-        public boolean isVarLength() {
-            return typelength == -1;
-        }
-
-        // return the alignment requirement of the type
-        public int getAlignment() {
-            return alignment;
-        }
-    }
-
-    /*
-     * Constants
-     */
-    private static final int PREV_VERSION = 1;
-    private static final int VERSION = 2; /* for backward compatibility */
-    private static final String CHARSET = "UTF-8";
-
-    /*
-     * Local variables
-     */
-    protected int[] colType;
-    protected Object[] colValue;
-    protected int alignmentOfEightBytes = 8;
-    protected byte errorFlag = 0;
-    protected int pktlen = EOF;
-
-    public int[] getColType() {
-        return colType;
-    }
-
-    /**
-     * An exception class for column type definition and
-     * set/get value mismatch.
-     */
-    public class TypeMismatchException extends IOException {
-        public TypeMismatchException(String msg) {
-            super(msg);
-        }
-    }
-
-    /**
-     * Empty Constructor
-     */
-    public GPDBWritable() {
-        initializeEightByteAlignment();
-    }
-
-    /**
-     * Constructor to build a db record. colType defines the schema
-     *
-     * @param columnType the table column types
-     */
-    public GPDBWritable(int[] columnType) {
-        initializeEightByteAlignment();
-        colType = columnType;
-        colValue = new Object[columnType.length];
-    }
-
-    /**
-     * Constructor to build a db record from a serialized form.
-     *
-     * @param data a record in the serialized form
-     * @throws IOException if the data is malformatted.
-     */
-    public GPDBWritable(byte[] data) throws IOException {
-        initializeEightByteAlignment();
-        ByteArrayInputStream bis = new ByteArrayInputStream(data);
-        DataInputStream dis = new DataInputStream(bis);
-
-        readFields(dis);
-    }
-
-    /*
-     * Read first 4 bytes, and verify it's a valid packet length.
-     * Upon error returns EOF.
-     */
-    private int readPktLen(DataInput in) throws IOException {
-        pktlen = EOF;
-
-        try {
-            pktlen = in.readInt();
-        } catch (EOFException e) {
-            Log.debug("Reached end of stream (EOFException)");
-            return EOF;
-        }
-        if (pktlen == EOF) {
-            Log.debug("Reached end of stream (returned -1)");
-        }
-
-        return pktlen;
-    }
-
-    @Override
-    public void readFields(DataInput in) throws IOException {
-        /*
-         * extract pkt len.
-		 *
-		 * GPSQL-1107:
-		 * The DataInput might already be empty (EOF), but we can't check it beforehand.
-		 * If that's the case, pktlen is updated to -1, to mark that the object is still empty.
-		 * (can be checked with isEmpty()).
-		 */
-        pktlen = readPktLen(in);
-        if (isEmpty()) {
-            return;
-        }
-
-		/* extract the version and col cnt */
-        int version = in.readShort();
-        int curOffset = 4 + 2;
-        int colCnt;
-
-		/* !!! Check VERSION !!! */
-        if (version != GPDBWritable.VERSION && version != GPDBWritable.PREV_VERSION) {
-            throw new IOException("Current GPDBWritable version(" +
-                    GPDBWritable.VERSION + ") does not match input version(" +
-                    version + ")");
-        }
-
-        if (version == GPDBWritable.VERSION) {
-            errorFlag = in.readByte();
-            curOffset += 1;
-        }
-
-        colCnt = in.readShort();
-        curOffset += 2;
-
-		/* Extract Column Type */
-        colType = new int[colCnt];
-        DBType[] coldbtype = new DBType[colCnt];
-        for (int i = 0; i < colCnt; i++) {
-            int enumType = (in.readByte());
-            curOffset += 1;
-            if (enumType == DBType.BIGINT.ordinal()) {
-                colType[i] = BIGINT.getOID();
-                coldbtype[i] = DBType.BIGINT;
-            } else if (enumType == DBType.BOOLEAN.ordinal()) {
-                colType[i] = BOOLEAN.getOID();
-                coldbtype[i] = DBType.BOOLEAN;
-            } else if (enumType == DBType.FLOAT8.ordinal()) {
-                colType[i] = FLOAT8.getOID();
-                coldbtype[i] = DBType.FLOAT8;
-            } else if (enumType == DBType.INTEGER.ordinal()) {
-                colType[i] = INTEGER.getOID();
-                coldbtype[i] = DBType.INTEGER;
-            } else if (enumType == DBType.REAL.ordinal()) {
-                colType[i] = REAL.getOID();
-                coldbtype[i] = DBType.REAL;
-            } else if (enumType == DBType.SMALLINT.ordinal()) {
-                colType[i] = SMALLINT.getOID();
-                coldbtype[i] = DBType.SMALLINT;
-            } else if (enumType == DBType.BYTEA.ordinal()) {
-                colType[i] = BYTEA.getOID();
-                coldbtype[i] = DBType.BYTEA;
-            } else if (enumType == DBType.TEXT.ordinal()) {
-                colType[i] = TEXT.getOID();
-                coldbtype[i] = DBType.TEXT;
-            } else {
-                throw new IOException("Unknown GPDBWritable.DBType ordinal value");
-            }
-        }
-
-		/* Extract null bit array */
-        byte[] nullbytes = new byte[getNullByteArraySize(colCnt)];
-        in.readFully(nullbytes);
-        curOffset += nullbytes.length;
-        boolean[] colIsNull = byteArrayToBooleanArray(nullbytes, colCnt);
-
-		/* extract column value */
-        colValue = new Object[colCnt];
-        for (int i = 0; i < colCnt; i++) {
-            if (!colIsNull[i]) {
-                /* Skip the alignment padding */
-                int skipbytes = roundUpAlignment(curOffset, coldbtype[i].getAlignment()) - curOffset;
-                for (int j = 0; j < skipbytes; j++) {
-                    in.readByte();
-                }
-                curOffset += skipbytes;
-
-				/* For fixed length type, increment the offset according to type type length here.
-                 * For var length type (BYTEA, TEXT), we'll read 4 byte length header and the
-				 * actual payload.
-				 */
-                int varcollen = -1;
-                if (coldbtype[i].isVarLength()) {
-                    varcollen = in.readInt();
-                    curOffset += 4 + varcollen;
-                } else {
-                    curOffset += coldbtype[i].getTypeLength();
-                }
-
-                switch (DataType.get(colType[i])) {
-                    case BIGINT: {
-                        colValue[i] = in.readLong();
-                        break;
-                    }
-                    case BOOLEAN: {
-                        colValue[i] = in.readBoolean();
-                        break;
-                    }
-                    case FLOAT8: {
-                        colValue[i] = in.readDouble();
-                        break;
-                    }
-                    case INTEGER: {
-                        colValue[i] = in.readInt();
-                        break;
-                    }
-                    case REAL: {
-                        colValue[i] = in.readFloat();
-                        break;
-                    }
-                    case SMALLINT: {
-                        colValue[i] = in.readShort();
-                        break;
-                    }
-
-					/* For BYTEA column, it has a 4 byte var length header. */
-                    case BYTEA: {
-                        colValue[i] = new byte[varcollen];
-                        in.readFully((byte[]) colValue[i]);
-                        break;
-                    }
-                    /* For text formatted column, it has a 4 byte var length header
-                     * and it's always null terminated string.
-					 * So, we can remove the last "\0" when constructing the string.
-					 */
-                    case TEXT: {
-                        byte[] data = new byte[varcollen];
-                        in.readFully(data, 0, varcollen);
-                        colValue[i] = new String(data, 0, varcollen - 1, CHARSET);
-                        break;
-                    }
-
-                    default:
-                        throw new IOException("Unknown GPDBWritable ColType");
-                }
-            }
-        }
-
-		/* Skip the ending alignment padding */
-        int skipbytes = roundUpAlignment(curOffset, 8) - curOffset;
-        for (int j = 0; j < skipbytes; j++) {
-            in.readByte();
-        }
-        curOffset += skipbytes;
-
-        if (errorFlag != 0) {
-            throw new IOException("Received error value " + errorFlag + " from format");
-        }
-    }
-
-    @Override
-    public void write(DataOutput out) throws IOException {
-        int numCol = colType.length;
-        boolean[] nullBits = new boolean[numCol];
-        int[] colLength = new int[numCol];
-        byte[] enumType = new byte[numCol];
-        int[] padLength = new int[numCol];
-        byte[] padbytes = new byte[8];
-
-        /**
-         * Compute the total payload and header length
-         * header = total length (4 byte), Version (2 byte), Error (1 byte), #col (2 byte)
-         * col type array = #col * 1 byte
-         * null bit array = ceil(#col/8)
-         */
-        int datlen = 4 + 2 + 1 + 2;
-        datlen += numCol;
-        datlen += getNullByteArraySize(numCol);
-
-        for (int i = 0; i < numCol; i++) {
-            /* Get the enum type */
-            DBType coldbtype;
-            switch (DataType.get(colType[i])) {
-                case BIGINT:
-                    coldbtype = DBType.BIGINT;
-                    break;
-                case BOOLEAN:
-                    coldbtype = DBType.BOOLEAN;
-                    break;
-                case FLOAT8:
-                    coldbtype = DBType.FLOAT8;
-                    break;
-                case INTEGER:
-                    coldbtype = DBType.INTEGER;
-                    break;
-                case REAL:
-                    coldbtype = DBType.REAL;
-                    break;
-                case SMALLINT:
-                    coldbtype = DBType.SMALLINT;
-                    break;
-                case BYTEA:
-                    coldbtype = DBType.BYTEA;
-                    break;
-                default:
-                    coldbtype = DBType.TEXT;
-            }
-            enumType[i] = (byte) (coldbtype.ordinal());
-
-			/* Get the actual value, and set the null bit */
-            if (colValue[i] == null) {
-                nullBits[i] = true;
-                colLength[i] = 0;
-            } else {
-                nullBits[i] = false;
-
-				/*
-                 * For fixed length type, we get the fixed length.
-				 * For var len binary format, the length is in the col value.
-				 * For text format, we must convert encoding first.
-				 */
-                if (!coldbtype.isVarLength()) {
-                    colLength[i] = coldbtype.getTypeLength();
-                } else if (!isTextForm(colType[i])) {
-                    colLength[i] = ((byte[]) colValue[i]).length;
-                } else {
-                    colLength[i] = ((String) colValue[i]).getBytes(CHARSET).length;
-                }
-
-				/* calculate and add the type alignment padding */
-                padLength[i] = roundUpAlignment(datlen, coldbtype.getAlignment()) - datlen;
-                datlen += padLength[i];
-
-				/* for variable length type, we add a 4 byte length header */
-                if (coldbtype.isVarLength()) {
-                    datlen += 4;
-                }
-            }
-            datlen += colLength[i];
-        }
-
-		/*
-		 * Add the final alignment padding for the next record
-		 */
-        int endpadding = roundUpAlignment(datlen, 8) - datlen;
-        datlen += endpadding;
-
-		/* Construct the packet header */
-        out.writeInt(datlen);
-        out.writeShort(VERSION);
-        out.writeByte(errorFlag);
-        out.writeShort(numCol);
-
-		/* Write col type */
-        for (int i = 0; i < numCol; i++) {
-            out.writeByte(enumType[i]);
-        }
-
-		/* Nullness */
-        byte[] nullBytes = boolArrayToByteArray(nullBits);
-        out.write(nullBytes);
-
-		/* Column Value */
-        for (int i = 0; i < numCol; i++) {
-            if (!nullBits[i]) {
-				/* Pad the alignment byte first */
-                if (padLength[i] > 0) {
-                    out.write(padbytes, 0, padLength[i]);
-                }
-
-				/* Now, write the actual column value */
-                switch (DataType.get(colType[i])) {
-                    case BIGINT:
-                        out.writeLong(((Long) colValue[i]));
-                        break;
-                    case BOOLEAN:
-                        out.writeBoolean(((Boolean) colValue[i]));
-                        break;
-                    case FLOAT8:
-                        out.writeDouble(((Double) colValue[i]));
-                        break;
-                    case INTEGER:
-                        out.writeInt(((Integer) colValue[i]));
-                        break;
-                    case REAL:
-                        out.writeFloat(((Float) colValue[i]));
-                        break;
-                    case SMALLINT:
-                        out.writeShort(((Short) colValue[i]));
-                        break;
-
-					/* For BYTEA format, add 4byte length header at the beginning  */
-                    case BYTEA:
-                        out.writeInt(colLength[i]);
-                        out.write((byte[]) colValue[i]);
-                        break;
-
-					/* For text format, add 4byte length header. string is already '\0' terminated */
-                    default: {
-                        out.writeInt(colLength[i]);
-                        byte[] data = ((String) colValue[i]).getBytes(CHARSET);
-                        out.write(data);
-                        break;
-                    }
-                }
-            }
-        }
-
-		/* End padding */
-        out.write(padbytes, 0, endpadding);
-    }
-
-    /**
-     * Private helper to convert boolean array to byte array
-     */
-    private static byte[] boolArrayToByteArray(boolean[] data) {
-        int len = data.length;
-        byte[] byts = new byte[getNullByteArraySize(len)];
-
-        for (int i = 0, j = 0, k = 7; i < data.length; i++) {
-            byts[j] |= (data[i] ? 1 : 0) << k--;
-            if (k < 0) {
-                j++;
-                k = 7;
-            }
-        }
-        return byts;
-    }
-
-    /**
-     * Private helper to determine the size of the null byte array
-     */
-    private static int getNullByteArraySize(int colCnt) {
-        return (colCnt / 8) + (colCnt % 8 != 0 ? 1 : 0);
-    }
-
-    /**
-     * Private helper to convert byte array to boolean array
-     */
-    private static boolean[] byteArrayToBooleanArray(byte[] data, int colCnt) {
-        boolean[] bools = new boolean[colCnt];
-        for (int i = 0, j = 0, k = 7; i < bools.length; i++) {
-            bools[i] = ((data[j] >> k--) & 0x01) == 1;
-            if (k < 0) {
-                j++;
-                k = 7;
-            }
-        }
-        return bools;
-    }
-
-    /**
-     * Private helper to round up alignment for the given length
-     */
-    private int roundUpAlignment(int len, int align) {
-        int commonAlignment = align;
-        if (commonAlignment == 8) {
-            commonAlignment = alignmentOfEightBytes;
-        }
-        return (((len) + ((commonAlignment) - 1)) & ~((commonAlignment) - 1));
-    }
-
-    /**
-     * Getter/Setter methods to get/set the column value
-     */
-
-    /**
-     * Sets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @param val    the value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public void setLong(int colIdx, Long val)
-            throws TypeMismatchException {
-        checkType(BIGINT, colIdx, true);
-        colValue[colIdx] = val;
-    }
-
-    /**
-     * Sets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @param val    the value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public void setBoolean(int colIdx, Boolean val)
-            throws TypeMismatchException {
-        checkType(BOOLEAN, colIdx, true);
-        colValue[colIdx] = val;
-    }
-
-    /**
-     * Sets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @param val    the value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public void setBytes(int colIdx, byte[] val)
-            throws TypeMismatchException {
-        checkType(BYTEA, colIdx, true);
-        colValue[colIdx] = val;
-    }
-
-    /**
-     * Sets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @param val    the value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public void setString(int colIdx, String val)
-            throws TypeMismatchException {
-        checkType(TEXT, colIdx, true);
-        if (val != null) {
-            colValue[colIdx] = val + "\0";
-        } else {
-            colValue[colIdx] = val;
-        }
-    }
-
-    /**
-     * Sets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @param val    the value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public void setFloat(int colIdx, Float val)
-            throws TypeMismatchException {
-        checkType(REAL, colIdx, true);
-        colValue[colIdx] = val;
-    }
-
-    /**
-     * Sets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @param val    the value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public void setDouble(int colIdx, Double val)
-            throws TypeMismatchException {
-        checkType(FLOAT8, colIdx, true);
-        colValue[colIdx] = val;
-    }
-
-    /**
-     * Sets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @param val    the value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public void setInt(int colIdx, Integer val)
-            throws TypeMismatchException {
-        checkType(INTEGER, colIdx, true);
-        colValue[colIdx] = val;
-    }
-
-    /**
-     * Sets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @param val    the value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public void setShort(int colIdx, Short val)
-            throws TypeMismatchException {
-        checkType(SMALLINT, colIdx, true);
-        colValue[colIdx] = val;
-    }
-
-    /**
-     * Gets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @return column value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public Long getLong(int colIdx)
-            throws TypeMismatchException {
-        checkType(BIGINT, colIdx, false);
-        return (Long) colValue[colIdx];
-    }
-
-    /**
-     * Gets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @return column value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public Boolean getBoolean(int colIdx)
-            throws TypeMismatchException {
-        checkType(BOOLEAN, colIdx, false);
-        return (Boolean) colValue[colIdx];
-    }
-
-    /**
-     * Gets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @return column value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public byte[] getBytes(int colIdx)
-            throws TypeMismatchException {
-        checkType(BYTEA, colIdx, false);
-        return (byte[]) colValue[colIdx];
-    }
-
-    /**
-     * Gets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @return column value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public String getString(int colIdx)
-            throws TypeMismatchException {
-        checkType(TEXT, colIdx, false);
-        return (String) colValue[colIdx];
-    }
-
-    /**
-     * Gets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @return column value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public Float getFloat(int colIdx)
-            throws TypeMismatchException {
-        checkType(REAL, colIdx, false);
-        return (Float) colValue[colIdx];
-    }
-
-    /**
-     * Gets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @return column value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public Double getDouble(int colIdx)
-            throws TypeMismatchException {
-        checkType(FLOAT8, colIdx, false);
-        return (Double) colValue[colIdx];
-    }
-
-    /**
-     * Gets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @return column value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public Integer getInt(int colIdx)
-            throws TypeMismatchException {
-        checkType(INTEGER, colIdx, false);
-        return (Integer) colValue[colIdx];
-    }
-
-    /**
-     * Gets the column value of the record.
-     *
-     * @param colIdx the column index
-     * @return column value
-     * @throws TypeMismatchException the column type does not match
-     */
-    public Short getShort(int colIdx)
-            throws TypeMismatchException {
-        checkType(SMALLINT, colIdx, false);
-        return (Short) colValue[colIdx];
-    }
-
-    /**
-     * Sets the error field.
-     *
-     * @param errorVal the error value
-     */
-    public void setError(boolean errorVal) {
-        errorFlag = errorVal ? (byte) 1 : (byte) 0;
-    }
-
-    /**
-     * Returns a string representation of the object.
-     */
-    @Override
-    public String toString() {
-        if (colType == null) {
-            return null;
-        }
-        StringBuilder result = new StringBuilder();
-        for (int i = 0; i < colType.length; i++) {
-            result.append("Column ").append(i).append(":");
-            if (colValue[i] != null) {
-                result.append(colType[i] == BYTEA.getOID()
-                        ? byteArrayInString((byte[]) colValue[i])
-                        : colValue[i]);
-            }
-            result.append("\n");
-        }
-        return result.toString();
-    }
-
-    /**
-     * Helper printing function
-     */
-    private static String byteArrayInString(byte[] data) {
-        StringBuilder result = new StringBuilder();
-        for (Byte b : data) {
-            result.append(b.intValue()).append(" ");
-        }
-        return result.toString();
-    }
-
-    /**
-     * Private Helper to check the type mismatch
-     * If the expected type is stored as string, then it must be set
-     * via setString.
-     * Otherwise, the type must match.
-     */
-    private void checkType(DataType inTyp, int idx, boolean isSet)
-            throws TypeMismatchException {
-        if (idx < 0 || idx >= colType.length) {
-            throw new TypeMismatchException("Column index is out of range");
-        }
-
-        int exTyp = colType[idx];
-
-        if (isTextForm(exTyp)) {
-            if (inTyp != TEXT) {
-                throw new TypeMismatchException(formErrorMsg(inTyp.getOID(), TEXT.getOID(), isSet));
-            }
-        } else if (inTyp != DataType.get(exTyp)) {
-            throw new TypeMismatchException(formErrorMsg(inTyp.getOID(), exTyp, isSet));
-        }
-    }
-
-    private String formErrorMsg(int inTyp, int colTyp, boolean isSet) {
-        return isSet
-                ? "Cannot set " + getTypeName(inTyp) + " to a " + getTypeName(colTyp) + " column"
-                : "Cannot get " + getTypeName(inTyp) + " from a " + getTypeName(colTyp) + " column";
-    }
-
-    /**
-     * Private Helper routine to tell whether a type is Text form or not
-     *
-     * @param type the type OID that we want to check
-     */
-    private boolean isTextForm(int type) {
-        return !Arrays.asList(BIGINT, BOOLEAN, BYTEA, FLOAT8, INTEGER, REAL, SMALLINT).contains(DataType.get(type));
-    }
-
-    /**
-     * Helper to get the type name.
-     * If a given oid is not in the commonly used list, we
-     * would expect a TEXT for it (for the error message).
-     *
-     * @param oid type OID
-     * @return type name
-     */
-    public static String getTypeName(int oid) {
-        switch (DataType.get(oid)) {
-            case BOOLEAN:
-                return "BOOLEAN";
-            case BYTEA:
-                return "BYTEA";
-            case CHAR:
-                return "CHAR";
-            case BIGINT:
-                return "BIGINT";
-            case SMALLINT:
-                return "SMALLINT";
-            case INTEGER:
-                return "INTEGER";
-            case TEXT:
-                return "TEXT";
-            case REAL:
-                return "REAL";
-            case FLOAT8:
-                return "FLOAT8";
-            case BPCHAR:
-                return "BPCHAR";
-            case VARCHAR:
-                return "VARCHAR";
-            case DATE:
-                return "DATE";
-            case TIME:
-                return "TIME";
-            case TIMESTAMP:
-                return "TIMESTAMP";
-            case NUMERIC:
-                return "NUMERIC";
-            default:
-                return "TEXT";
-        }
-    }
-
-    /*
-     * Get alignment from command line to match to the alignment
-     * the C code uses (see gphdfs/src/protocol_formatter/common.c).
-     */
-    private void initializeEightByteAlignment() {
-        String alignment = System.getProperty("greenplum.alignment");
-        if (alignment == null) {
-            return;
-        }
-        alignmentOfEightBytes = Integer.parseInt(alignment);
-    }
-
-    /**
-     * Returns if the writable object is empty,
-     * based on the pkt len as read from stream.
-     * -1 means nothing was read (eof).
-     *
-     * @return whether the writable object is empty
-     */
-    public boolean isEmpty() {
-        return pktlen == EOF;
-    }
-}



Mime
View raw message