public void testReadTimestampFormat_0_11(string readerTimeZone)
        {
            string oldFilePath = Path.Combine(TestHelpers.ResourcesDirectory, "orc-file-11-format.orc");

            using (TestHelpers.SetTimeZoneInfo(readerTimeZone))
            {
                Reader reader = OrcFile.createReader(oldFilePath, OrcFile.readerOptions(conf));

                StructObjectInspector    readerInspector = (StructObjectInspector)reader.getObjectInspector();
                IList <StructField>      fields          = readerInspector.getAllStructFieldRefs();
                TimestampObjectInspector tso             = (TimestampObjectInspector)readerInspector
                                                           .getStructFieldRef("ts").getFieldObjectInspector();

                using (RecordReader rows = reader.rows())
                {
                    object row = rows.next();
                    Assert.NotNull(row);
                    Assert.Equal(Timestamp.Parse("2000-03-12 15:00:00"),
                                 tso.getPrimitiveJavaObject(readerInspector.getStructFieldData(row,
                                                                                               fields[12])));

                    // check the contents of second row
                    Assert.Equal(true, rows.hasNext());
                    rows.seekToRow(7499);
                    row = rows.next();
                    Assert.Equal(Timestamp.Parse("2000-03-12 15:00:01"),
                                 tso.getPrimitiveJavaObject(readerInspector.getStructFieldData(row,
                                                                                               fields[12])));

                    Assert.Equal(false, rows.hasNext());
                }
            }
        }
 public override object getStructFieldData(object data, StructField fieldRef)
 {
     // For performance don't check that that the fieldRef isn't recId everytime,
     // just assume that the caller used getAllStructFieldRefs and thus doesn't have that fieldRef
     return(wrapped.getStructFieldData(data, fieldRef));
 }
Beispiel #3
0
        public void testStringAndBinaryStatistics()
        {
            ObjectInspector inspector = ObjectInspectorFactory.getReflectionObjectInspector(typeof(SimpleStruct));

            using (Stream file = File.OpenWrite(TestFilePath))
                using (Writer writer = OrcFile.createWriter(TestFilePath, file, OrcFile.writerOptions(conf)
                                                            .inspector(inspector)
                                                            .stripeSize(100000)
                                                            .bufferSize(10000)))
                {
                    writer.addRow(new SimpleStruct(bytes(0, 1, 2, 3, 4), "foo"));
                    writer.addRow(new SimpleStruct(bytes(0, 1, 2, 3), "bar"));
                    writer.addRow(new SimpleStruct(bytes(0, 1, 2, 3, 4, 5), null));
                    writer.addRow(new SimpleStruct(null, "hi"));
                    writer.close();

                    Assert.Equal(4, writer.getNumberOfRows());
                    Assert.Equal(273, writer.getRawDataSize());
                }

            Reader reader = OrcFile.createReader(TestFilePath,
                                                 OrcFile.readerOptions(conf));

            Assert.Equal(4, reader.getNumberOfRows());
            Assert.Equal(273, reader.getRawDataSize());
            Assert.Equal(15, reader.getRawDataSizeOfColumns(Lists.newArrayList("bytes1")));
            Assert.Equal(258, reader.getRawDataSizeOfColumns(Lists.newArrayList("string1")));
            Assert.Equal(273, reader.getRawDataSizeOfColumns(Lists.newArrayList("bytes1", "string1")));

            // check the stats
            ColumnStatistics[] stats = reader.getStatistics();
            Assert.Equal(4, stats[0].getNumberOfValues());
            Assert.Equal("count: 4 hasNull: False", stats[0].ToString());

            Assert.Equal(3, stats[1].getNumberOfValues());
            Assert.Equal(15, ((BinaryColumnStatistics)stats[1]).getSum());
            Assert.Equal("count: 3 hasNull: True sum: 15", stats[1].ToString());

            Assert.Equal(3, stats[2].getNumberOfValues());
            Assert.Equal("bar", ((StringColumnStatistics)stats[2]).getMinimum());
            Assert.Equal("hi", ((StringColumnStatistics)stats[2]).getMaximum());
            Assert.Equal(8, ((StringColumnStatistics)stats[2]).getSum());
            Assert.Equal("count: 3 hasNull: True min: bar max: hi sum: 8",
                         stats[2].ToString());

            // check the inspectors
            StructObjectInspector readerInspector =
                (StructObjectInspector)reader.getObjectInspector();

            Assert.Equal(ObjectInspectorCategory.STRUCT, readerInspector.getCategory());
            Assert.Equal("struct<bytes1:binary,string1:string>", readerInspector.getTypeName());
            IList <StructField>   fields = readerInspector.getAllStructFieldRefs();
            BinaryObjectInspector bi     = (BinaryObjectInspector)readerInspector.
                                           getStructFieldRef("bytes1").getFieldObjectInspector();
            StringObjectInspector st = (StringObjectInspector)readerInspector.
                                       getStructFieldRef("string1").getFieldObjectInspector();

            using (RecordReader rows = reader.rows())
            {
                object row = rows.next();
                Assert.NotNull(row);
                // check the contents of the first row
                Assert.Equal(bytes(0, 1, 2, 3, 4), bi.get(
                                 readerInspector.getStructFieldData(row, fields[0])));
                Assert.Equal("foo", st.getPrimitiveJavaObject(readerInspector.
                                                              getStructFieldData(row, fields[1])));

                // check the contents of second row
                Assert.Equal(true, rows.hasNext());
                row = rows.next();
                Assert.Equal(bytes(0, 1, 2, 3), bi.get(
                                 readerInspector.getStructFieldData(row, fields[0])));
                Assert.Equal("bar", st.getPrimitiveJavaObject(readerInspector.
                                                              getStructFieldData(row, fields[1])));

                // check the contents of second row
                Assert.Equal(true, rows.hasNext());
                row = rows.next();
                Assert.Equal(bytes(0, 1, 2, 3, 4, 5), bi.get(
                                 readerInspector.getStructFieldData(row, fields[0])));
                Assert.Null(st.getPrimitiveJavaObject(readerInspector.
                                                      getStructFieldData(row, fields[1])));

                // check the contents of second row
                Assert.Equal(true, rows.hasNext());
                row = rows.next();
                Assert.Null(bi.get(
                                readerInspector.getStructFieldData(row, fields[0])));
                Assert.Equal("hi", st.getPrimitiveJavaObject(readerInspector.
                                                             getStructFieldData(row, fields[1])));

                Assert.Equal(false, rows.hasNext());
            }
        }