diff --git build-common.xml build-common.xml index ac9b4f5..8740772 100644 --- build-common.xml +++ build-common.xml @@ -40,6 +40,7 @@ deprecation="false" sourcepath="" includes="**/*.java" + debug="${javac.debug}" encoding="utf-8" srcdir="@{srcDir}" destdir="@{destDir}" diff --git src/java/org/apache/hcatalog/common/HCatUtil.java src/java/org/apache/hcatalog/common/HCatUtil.java index 27adde6..bee4210 100644 --- src/java/org/apache/hcatalog/common/HCatUtil.java +++ src/java/org/apache/hcatalog/common/HCatUtil.java @@ -208,8 +208,7 @@ public class HCatUtil { * @return HCatSchema instance which contains the partition columns * @throws IOException */ - public static HCatSchema getPartitionColumns(Table table) - throws IOException { + public static HCatSchema getPartitionColumns(Table table) throws IOException { HCatSchema cols = new HCatSchema(new LinkedList()); if (table.getPartitionKeys().size() != 0) { for (FieldSchema fs : table.getPartitionKeys()) { diff --git src/java/org/apache/hcatalog/data/LazyHCatRecord.java src/java/org/apache/hcatalog/data/LazyHCatRecord.java index 51e9857..9917f5c 100644 --- src/java/org/apache/hcatalog/data/LazyHCatRecord.java +++ src/java/org/apache/hcatalog/data/LazyHCatRecord.java @@ -42,7 +42,7 @@ public class LazyHCatRecord extends HCatRecord { public static final Logger LOG = LoggerFactory.getLogger(LazyHCatRecord.class.getName()); - private Object o; + private Object wrappedObject; private StructObjectInspector soi; @Override @@ -50,7 +50,7 @@ public class LazyHCatRecord extends HCatRecord { try { StructField fref = soi.getAllStructFieldRefs().get(fieldNum); return HCatRecordSerDe.serializeField( - soi.getStructFieldData(o, fref), + soi.getStructFieldData(wrappedObject, fref), fref.getFieldObjectInspector()); } catch (SerDeException e) { throw new IllegalStateException("SerDe Exception deserializing",e); @@ -115,18 +115,14 @@ public class LazyHCatRecord extends HCatRecord { throw new UnsupportedOperationException("not allowed to run copy() on LazyHCatRecord"); } - public LazyHCatRecord(Object o, ObjectInspector oi) - throws Exception { - + public LazyHCatRecord(Object wrappedObject, ObjectInspector oi) throws Exception { if (oi.getCategory() != Category.STRUCT) { - throw new SerDeException(getClass().toString() - + " can only make a lazy hcat record from objects of " + - "struct types, but we got: " - + oi.getTypeName()); + throw new SerDeException(getClass().toString() + " can only make a lazy hcat record from " + + "objects of struct types, but we got: " + oi.getTypeName()); } this.soi = (StructObjectInspector)oi; - this.o = o; + this.wrappedObject = wrappedObject; } @Override diff --git src/test/org/apache/hcatalog/data/TestLazyHCatRecord.java src/test/org/apache/hcatalog/data/TestLazyHCatRecord.java index 7187788..9b5f7e5 100644 --- src/test/org/apache/hcatalog/data/TestLazyHCatRecord.java +++ src/test/org/apache/hcatalog/data/TestLazyHCatRecord.java @@ -24,48 +24,50 @@ import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; import org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; - import org.apache.hcatalog.data.schema.HCatSchema; import org.apache.hcatalog.data.schema.HCatSchemaUtils; +import org.junit.Assert; +import org.junit.Test; -import junit.framework.TestCase; - -public class TestLazyHCatRecord extends TestCase{ +public class TestLazyHCatRecord { private final int INT_CONST = 789; private final long LONG_CONST = 5000000000L; private final double DOUBLE_CONST = 3.141592654; private final String STRING_CONST = "hello world"; - + @Test public void testGet() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()); - assertEquals(INT_CONST, ((Integer)r.get(0)).intValue()); - assertEquals(LONG_CONST, ((Long)r.get(1)).longValue()); - assertEquals(DOUBLE_CONST, ((Double)r.get(2)).doubleValue()); - assertEquals(STRING_CONST, (String)r.get(3)); + Assert.assertEquals(INT_CONST, ((Integer) r.get(0)).intValue()); + Assert.assertEquals(LONG_CONST, ((Long) r.get(1)).longValue()); + Assert.assertEquals(DOUBLE_CONST, ((Double) r.get(2)).doubleValue(), 0); + Assert.assertEquals(STRING_CONST, (String) r.get(3)); } + @Test public void testGetWithName() throws Exception { TypeInfo ti = getTypeInfo(); HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector(ti)); HCatSchema schema = HCatSchemaUtils.getHCatSchema(ti) .get(0).getStructSubSchema(); - assertEquals(INT_CONST, ((Integer)r.get("an_int", schema)).intValue()); - assertEquals(LONG_CONST, ((Long)r.get("a_long", schema)).longValue()); - assertEquals(DOUBLE_CONST, ((Double)r.get("a_double", schema)).doubleValue()); - assertEquals(STRING_CONST, (String)r.get("a_string", schema)); + Assert.assertEquals(INT_CONST, ((Integer) r.get("an_int", schema)).intValue()); + Assert.assertEquals(LONG_CONST, ((Long) r.get("a_long", schema)).longValue()); + Assert.assertEquals(DOUBLE_CONST, ((Double) r.get("a_double", schema)).doubleValue(), 0); + Assert.assertEquals(STRING_CONST, (String) r.get("a_string", schema)); } + @Test public void testGetAll() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()); List list = r.getAll(); - assertEquals(INT_CONST, ((Integer)list.get(0)).intValue()); - assertEquals(LONG_CONST, ((Long)list.get(1)).longValue()); - assertEquals(DOUBLE_CONST, ((Double)list.get(2)).doubleValue()); - assertEquals(STRING_CONST, (String)list.get(3)); + Assert.assertEquals(INT_CONST, ((Integer) list.get(0)).intValue()); + Assert.assertEquals(LONG_CONST, ((Long) list.get(1)).longValue()); + Assert.assertEquals(DOUBLE_CONST, ((Double) list.get(2)).doubleValue(), 0); + Assert.assertEquals(STRING_CONST, (String) list.get(3)); } + @Test public void testSet() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()); boolean sawException = false; @@ -74,14 +76,16 @@ public class TestLazyHCatRecord extends TestCase{ } catch (UnsupportedOperationException uoe) { sawException = true; } - assertTrue(sawException); + Assert.assertTrue(sawException); } + @Test public void testSize() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()); - assertEquals(4, r.size()); + Assert.assertEquals(4, r.size()); } + @Test public void testReadFields() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()); boolean sawException = false; @@ -90,9 +94,10 @@ public class TestLazyHCatRecord extends TestCase{ } catch (UnsupportedOperationException uoe) { sawException = true; } - assertTrue(sawException); + Assert.assertTrue(sawException); } + @Test public void testWrite() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()); boolean sawException = false; @@ -101,9 +106,10 @@ public class TestLazyHCatRecord extends TestCase{ } catch (UnsupportedOperationException uoe) { sawException = true; } - assertTrue(sawException); + Assert.assertTrue(sawException); } + @Test public void testSetWithName() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()); boolean sawException = false; @@ -112,9 +118,10 @@ public class TestLazyHCatRecord extends TestCase{ } catch (UnsupportedOperationException uoe) { sawException = true; } - assertTrue(sawException); + Assert.assertTrue(sawException); } + @Test public void testRemove() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()); boolean sawException = false; @@ -123,9 +130,10 @@ public class TestLazyHCatRecord extends TestCase{ } catch (UnsupportedOperationException uoe) { sawException = true; } - assertTrue(sawException); + Assert.assertTrue(sawException); } + @Test public void testCopy() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()); boolean sawException = false; @@ -134,19 +142,19 @@ public class TestLazyHCatRecord extends TestCase{ } catch (UnsupportedOperationException uoe) { sawException = true; } - assertTrue(sawException); + Assert.assertTrue(sawException); } + @Test public void testGetWritable() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()).getWritable(); - assertEquals(INT_CONST, ((Integer)r.get(0)).intValue()); - assertEquals(LONG_CONST, ((Long)r.get(1)).longValue()); - assertEquals(DOUBLE_CONST, ((Double)r.get(2)).doubleValue()); - assertEquals(STRING_CONST, (String)r.get(3)); - assertEquals("org.apache.hcatalog.data.DefaultHCatRecord", r.getClass().getName()); + Assert.assertEquals(INT_CONST, ((Integer) r.get(0)).intValue()); + Assert.assertEquals(LONG_CONST, ((Long) r.get(1)).longValue()); + Assert.assertEquals(DOUBLE_CONST, ((Double) r.get(2)).doubleValue(), 0); + Assert.assertEquals(STRING_CONST, (String) r.get(3)); + Assert.assertEquals("org.apache.hcatalog.data.DefaultHCatRecord", r.getClass().getName()); } - private HCatRecord getHCatRecord() throws Exception { List rec_1 = new ArrayList(4); diff --git src/test/org/apache/hcatalog/data/TestReaderWriter.java src/test/org/apache/hcatalog/data/TestReaderWriter.java index c7c0b09..a682855 100644 --- src/test/org/apache/hcatalog/data/TestReaderWriter.java +++ src/test/org/apache/hcatalog/data/TestReaderWriter.java @@ -32,12 +32,8 @@ import java.util.Map; import java.util.Map.Entry; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hive.cli.CliSessionState; -import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.ql.CommandNeedRetryException; -import org.apache.hadoop.hive.ql.Driver; -import org.apache.hadoop.hive.ql.session.SessionState; import org.apache.hadoop.mapreduce.InputSplit; import org.apache.hcatalog.common.HCatException; import org.apache.hcatalog.data.transfer.DataTransferFactory; @@ -47,21 +43,19 @@ import org.apache.hcatalog.data.transfer.ReadEntity; import org.apache.hcatalog.data.transfer.ReaderContext; import org.apache.hcatalog.data.transfer.WriteEntity; import org.apache.hcatalog.data.transfer.WriterContext; +import org.apache.hcatalog.mapreduce.HCatBaseTest; import org.junit.Assert; import org.junit.Test; -public class TestReaderWriter { +public class TestReaderWriter extends HCatBaseTest { @Test public void test() throws MetaException, CommandNeedRetryException, IOException, ClassNotFoundException { - HiveConf conf = new HiveConf(getClass()); - Driver driver = new Driver(conf); - SessionState.start(new CliSessionState(conf)); driver.run("drop table mytbl"); driver.run("create table mytbl (a string, b int)"); - Iterator> itr = conf.iterator(); + Iterator> itr = hiveConf.iterator(); Map map = new HashMap(); while (itr.hasNext()) { Entry kv = itr.next();