public void Basics() { Field.Builder fb = new Field.Builder(); Field f0_nullable = fb.Name("f0").DataType(Int32Type.Default).Build(); Field f0_nonnullable = fb.Name("f0").DataType(Int32Type.Default).Nullable(false).Build(); Assert.True(f0_nullable.Name == "f0"); Assert.True(f0_nullable.DataType.Name == Int32Type.Default.Name); Assert.True(f0_nullable.IsNullable); Assert.False(f0_nonnullable.IsNullable); }
public void TestTableFromRecordBatches() { RecordBatch recordBatch1 = TestData.CreateSampleRecordBatch(length: 10, true); RecordBatch recordBatch2 = TestData.CreateSampleRecordBatch(length: 10, true); IList <RecordBatch> recordBatches = new List <RecordBatch>() { recordBatch1, recordBatch2 }; Table table1 = Table.TableFromRecordBatches(recordBatch1.Schema, recordBatches); Assert.Equal(20, table1.RowCount); Assert.Equal(21, table1.ColumnCount); FixedSizeBinaryType type = new FixedSizeBinaryType(17); Field newField1 = new Field(type.Name, type, false); Schema newSchema1 = recordBatch1.Schema.SetField(20, newField1); Assert.Throws <ArgumentException>(() => Table.TableFromRecordBatches(newSchema1, recordBatches)); List <Field> fields = new List <Field>(); Field.Builder fieldBuilder = new Field.Builder(); fields.Add(fieldBuilder.Name("Ints").DataType(Int32Type.Default).Nullable(true).Build()); fieldBuilder = new Field.Builder(); fields.Add(fieldBuilder.Name("Strings").DataType(StringType.Default).Nullable(true).Build()); StructType structType = new StructType(fields); Field newField2 = new Field(structType.Name, structType, false); Schema newSchema2 = recordBatch1.Schema.SetField(16, newField2); Assert.Throws <ArgumentException>(() => Table.TableFromRecordBatches(newSchema2, recordBatches)); }
private static void CreateField(Field.Builder builder, JsonField jsonField) { builder.Name(jsonField.Name) .DataType(ToArrowType(jsonField.Type)) .Nullable(jsonField.Nullable); if (jsonField.Metadata != null) { builder.Metadata(jsonField.Metadata); } }
public void TestStructArray() { // The following can be improved with a Builder class for StructArray. List <Field> fields = new List <Field>(); Field.Builder fieldBuilder = new Field.Builder(); fields.Add(fieldBuilder.Name("Strings").DataType(StringType.Default).Nullable(true).Build()); fieldBuilder = new Field.Builder(); fields.Add(fieldBuilder.Name("Ints").DataType(Int32Type.Default).Nullable(true).Build()); StructType structType = new StructType(fields); StringArray.Builder stringBuilder = new StringArray.Builder(); StringArray stringArray = stringBuilder.Append("joe").AppendNull().AppendNull().Append("mark").Build(); Int32Array.Builder intBuilder = new Int32Array.Builder(); Int32Array intArray = intBuilder.Append(1).Append(2).AppendNull().Append(4).Build(); List <Array> arrays = new List <Array>(); arrays.Add(stringArray); arrays.Add(intArray); ArrowBuffer.BitmapBuilder nullBitmap = new ArrowBuffer.BitmapBuilder(); var nullBitmapBuffer = nullBitmap.Append(true).Append(true).Append(false).Append(true).Build(); StructArray structs = new StructArray(structType, 4, arrays, nullBitmapBuffer, 1); Assert.Equal(4, structs.Length); Assert.Equal(1, structs.NullCount); ArrayData[] childArrays = structs.Data.Children; // Data for StringArray and Int32Array Assert.Equal(2, childArrays.Length); for (int i = 0; i < childArrays.Length; i++) { ArrayData arrayData = childArrays[i]; Assert.Null(arrayData.Children); if (i == 0) { Assert.Equal(ArrowTypeId.String, arrayData.DataType.TypeId); Array array = new StringArray(arrayData); StringArray structStringArray = array as StringArray; Assert.NotNull(structStringArray); Assert.Equal(structs.Length, structStringArray.Length); Assert.Equal(stringArray.Length, structStringArray.Length); Assert.Equal(stringArray.NullCount, structStringArray.NullCount); for (int j = 0; j < stringArray.Length; j++) { Assert.Equal(stringArray.GetString(j), structStringArray.GetString(j)); } } if (i == 1) { Assert.Equal(ArrowTypeId.Int32, arrayData.DataType.TypeId); Array array = new Int32Array(arrayData); Int32Array structIntArray = array as Int32Array; Assert.NotNull(structIntArray); Assert.Equal(structs.Length, structIntArray.Length); Assert.Equal(intArray.Length, structIntArray.Length); Assert.Equal(intArray.NullCount, structIntArray.NullCount); for (int j = 0; j < intArray.Length; j++) { Assert.Equal(intArray.GetValue(j), structIntArray.GetValue(j)); } } } }