You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@arrow.apache.org by swizz one <so...@gmail.com> on 2020/05/05 05:42:59 UTC

Fixed array created with buffer

Please, I am trying to make a fix size array without using the append
method but i keep getting the wrong number read out. I am thinking that the
array is not reading the correct buffer. The code is the follwing

GError *error = NULL;
  // First we create the array for each of the members of the position
structure object
  GArrowFloatArray * x_array;
  GArrowFloatArray * y_array;
  GArrowFloatArray * z_array;

  // The number of rows per record batch/ array would be 500
  // defining array length which must be equal for all array

  gint64 len = 2;
  // not Null element in the array- GArrowBuffer *data = NULL
  // no Null element -> gint64 n_nulls = 0;

  // creating the data to input into the array
  GArrowBuffer * x_buffer;
  GArrowBuffer * y_buffer;
  GArrowBuffer * z_buffer;

  guint8 data_x[len];
  guint8 data_y[len];
  guint8 data_z[len];
  //generating the values
  for ( int i = 0; i < len; i++){
    data_x[i] = 1;
    data_y[i] = 1;
    data_z[i] = 1;
    g_print("%d ", data_x[i]);
    g_print("%d ", data_y[i]);
    g_print("%d ", data_z[i]);

  }




  // Creating the buffer
  x_buffer = garrow_buffer_new(data_x, len * sizeof(gint64));
  y_buffer = garrow_buffer_new(data_y, len* sizeof(gint64));
  z_buffer = garrow_buffer_new(data_z, len* sizeof(gint64));

  // creating arrow float aray
  x_array = garrow_float_array_new(len, x_buffer, NULL, 0);
  y_array = garrow_float_array_new(len, y_buffer, NULL, 0);
  z_array = garrow_float_array_new(len, z_buffer, NULL, 0);
  //g_print("%s", garrow_array_to_string (GARROW_ARRAY(x_array),NULL));
  const gfloat * to_print = garrow_float_array_get_values (x_array,&len);
  g_print("%g\n", *to_print);
  // declaring fields
  GArrowField *field_x, *field_y, *field_z;
  // all the array are the same type
  // finding the data type
  //GArrowDataType * data_type_x =
garrow_array_get_value_data_type(x_array);
  // GArrowDataType * data_type_y =
garrow_array_get_value_data_type(x_array);
  // GArrowDataType * data_type_z =
garrow_array_get_value_data_type(x_array);

  field_x = garrow_field_new ("x_column",
GARROW_DATA_TYPE(garrow_float_data_type_new()));
  field_y = garrow_field_new ("y_column",
GARROW_DATA_TYPE(garrow_float_data_type_new()));
  field_z = garrow_field_new ("z_column",
GARROW_DATA_TYPE(garrow_float_data_type_new()));




Result

1 1 1 1 1 1 2.36943e-38
x_column:   [
    2.36943e-38,
    1.34222e+08
  ]
y_column:   [
    2.36943e-38,
    0.000265695
  ]
z_column:   [
    1.34222e+08,
    -1.0248e-23
  ]
columns[0](x_column): [2.36943e-38, 1.34222e+08]
columns[1](y_column): [2.36943e-38, 0.000265695]
columns[2](z_column): [1.34222e+08, -1.0248e-23]