예제 #1
0
        public static Array MakeArrayBuffer <T>(IArrowType dataType,
                                                int length,
                                                IEnumerable <T> data)
            where T : struct
        {
            ArrowBuffer.Builder <T> builder = new ArrowBuffer.Builder <T>();

            builder.AppendRange(data);

            ArrowBuffer buffer = builder.Build();

            ArrayData arrayData = new ArrayData(dataType,
                                                length,
                                                0,
                                                0,
                                                new[]
            {
                buffer
            });

            Array array = ArrowArrayFactory.BuildArray(arrayData) as Array;

            return(array);
        }
예제 #2
0
        public static Table BuildTable(List <TDataLayout> data)
        {
            PropertyInfo[] properties = typeof(TDataLayout).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetCustomAttribute <ArrowPropertyAttribute>() != null).ToArray();

            //int length = data.Count;

            List <Field> fields = new List <Field>(properties.Length);

            Apache.Arrow.Schema.Builder schemaBuilder = new Apache.Arrow.Schema.Builder();

            foreach (PropertyInfo property in properties)
            {
                ArrowPropertyAttribute arrowPropertyAttribute = property.GetCustomAttribute <ArrowPropertyAttribute>();

                Field field = new Field.Builder().Name(arrowPropertyAttribute.Name).DataType(arrowPropertyAttribute.ArrowType()).Build();

                schemaBuilder.Field(field);

                fields.Add(field);
            }

            List <List <object> > transformData = new List <List <object> >(properties.Length);

            for (int i = 0; i < properties.Length; ++i)
            {
                transformData.Add(new List <object>(data.Count));
            }

            for (int i = 0; i < data.Count; ++i)
            {
                int j = 0;

                foreach (object property in data[i])
                {
                    transformData[j++][i] = property;
                }
            }

            List <Column> columns = new List <Column>(properties.Length);

            for (int i = 0; i < properties.Length; ++i)
            {
                Array array = ArrowUtilities.MakeArrayBuffer(fields[i].DataType,
                                                             transformData[i]);

                Column column = new Column(fields[i],
                                           new Array[]
                {
                    array
                });

                columns.Add(column);
            }

            //NativeMemoryAllocator memoryAllocator = new NativeMemoryAllocator(32);

            Table table = new Table(schemaBuilder.Build(),
                                    columns);

            return(table);
        }