Пример #1
0
        public void EndToEnd()
        {
            using (var stream = new MemoryStream()) {
                using (var writer = new FeatherWriter(stream)) {
                    var payload = new ClassicEncoder();
                    payload.WriteUInt32(1);
                    payload.WriteBoolean(true);
                    payload.WriteString("test");
                    writer.Write(payload);

                    payload = new ClassicEncoder();
                    payload.WriteUInt32(2);
                    payload.WriteBoolean(false);
                    payload.WriteNullableString(null);
                    writer.Write(payload);
                }

                stream.Position = 0;

                using (var reader = new FeatherReader(stream)) {
                    var payload2 = reader.Read <ClassicDecoder>();
                    Assert.AreEqual((UInt32)1, payload2.ReadUInt32());
                    Assert.AreEqual(true, payload2.ReadBoolean());
                    Assert.AreEqual("test", payload2.ReadString());

                    payload2 = reader.Read <ClassicDecoder>();
                    Assert.AreEqual((UInt32)2, payload2.ReadUInt32());
                    Assert.AreEqual(false, payload2.ReadBoolean());
                    Assert.AreEqual(null, payload2.ReadNullableString());

                    Assert.AreEqual(null, reader.Read <ClassicDecoder>());
                }
            }
        }
Пример #2
0
        public void Write_Multiple()
        {
            using (var stream = new MemoryStream()) {
                // Write to stream
                using (var writer = new FeatherWriter(stream)) {
                    writer.Write(new[] { Payload, Payload });
                }

                Assert.AreEqual("1,true,test\n1,true,test\n", Encoding.UTF8.GetString(stream.ToArray()));
            }
        }
Пример #3
0
        }                                                   // set in Timestamp

        // not implemented: user_metadata (see: https://github.com/wesm/feather/blob/master/cpp/src/feather/metadata.fbs#L106)

        public void CreateMetadata(FlatBuffers.FlatBufferBuilder builder, FeatherWriter writer, out int metadataOffset, out feather.fbs.TypeMetadata metadata, out FlatBuffers.Offset <feather.fbs.PrimitiveArray> categoryLevels)
        {
            var isCategoryType =
                Type == ColumnType.Category ||
                Type == ColumnType.NullableCategory;

            var isDateType =
                Type == ColumnType.Date ||
                Type == ColumnType.NullableDate;

            var isTimeType =
                Type == ColumnType.Time_Microsecond ||
                Type == ColumnType.Time_Millisecond ||
                Type == ColumnType.Time_Second ||
                Type == ColumnType.Time_Nanosecond ||
                Type == ColumnType.NullableTime_Microsecond ||
                Type == ColumnType.NullableTime_Millisecond ||
                Type == ColumnType.NullableTime_Second ||
                Type == ColumnType.NullableTime_Nanosecond;

            var isTimestampType =
                Type == ColumnType.Timestamp_Microsecond ||
                Type == ColumnType.Timestamp_Millisecond ||
                Type == ColumnType.Timestamp_Second ||
                Type == ColumnType.Timestamp_Nanosecond ||
                Type == ColumnType.NullableTimestamp_Microsecond ||
                Type == ColumnType.NullableTimestamp_Millisecond ||
                Type == ColumnType.NullableTimestamp_Second ||
                Type == ColumnType.NullableTimestamp_Nanosecond;

            if (isDateType)
            {
                throw new InvalidOperationException($"Mapping to a Date on disk doesn't make sense from .NET");
            }

            if (isTimestampType)
            {
                var offsetMeta =
                    feather.fbs.TimestampMetadata.CreateTimestampMetadata(
                        builder,
                        Unit.MapToDiskType(),
                        builder.CreateString("GMT")
                        );
                metadataOffset = offsetMeta.Value;
                metadata       = feather.fbs.TypeMetadata.TimestampMetadata;
                categoryLevels = default(FlatBuffers.Offset <feather.fbs.PrimitiveArray>);
                return;
            }

            if (isTimeType)
            {
                var offsetMeta =
                    feather.fbs.TimeMetadata.CreateTimeMetadata(
                        builder,
                        Unit.MapToDiskType()
                        );
                metadataOffset = offsetMeta.Value;
                metadata       = feather.fbs.TypeMetadata.TimeMetadata;
                categoryLevels = default(FlatBuffers.Offset <feather.fbs.PrimitiveArray>);
                return;
            }

            if (isCategoryType)
            {
                long startIx;
                long numBytes;
                writer.WriteLevels(Levels, out startIx, out numBytes);

                categoryLevels =
                    feather.fbs.PrimitiveArray.CreatePrimitiveArray(
                        builder,
                        feather.fbs.Type.UTF8,
                        feather.fbs.Encoding.PLAIN,
                        startIx,
                        Levels.LongLength,
                        0,
                        numBytes
                        );

                var offsetMeta =
                    feather.fbs.CategoryMetadata.CreateCategoryMetadata(
                        builder,
                        categoryLevels,
                        Ordered
                        );

                metadataOffset = offsetMeta.Value;
                metadata       = feather.fbs.TypeMetadata.CategoryMetadata;
                return;
            }

            metadataOffset = 0;
            metadata       = feather.fbs.TypeMetadata.NONE;
            categoryLevels = default(FlatBuffers.Offset <feather.fbs.PrimitiveArray>);
        }