Hey,

that is, although not very elegant a very common pattern in Java and is e.g. 
also used by Apache Calcite internally. There a "Table Scan" is roughly 
representat as an Object[][]. It would be more elegant to use Generics but as 
Yuan states the first dimension of the array dictates the rows and the second 
the columns. So we could only end up with something like
TupleN<TYPE_COL_1, TYPE_COL_2, TYPE_COL_3, ...>[] where we would need to have 
classes for all these Tuple_N's.
And as they all have a different amount of dependant generic parameters we 
could not abstract that type away.
So you go back to Object[][] and basically tell the computer to not care about 
types here as you know what you are doing (and you better do...).

Best
Julian
________________________________
Von: Yuan Tian <jackietie...@gmail.com>
Gesendet: Mittwoch, 29. September 2021 09:25
An: dev@iotdb.apache.org <dev@iotdb.apache.org>
Betreff: Re: Use of generics.

Hi,
In Java, array is also an object, so the` Object[] values` in Tablet.java
is a two-dimension array. Object represents arrays of different type.

Java doesn't have class member function template, however maybe in C++, you
can use that feature to improve the performance. But even in this way, we
cannot only contains 'primitive" types array in tablet, because different
sensors in this tablet may have different types and the number of the
sensors are also unknown.

But you can use variadic template feature introduced since C++11 to fix
that. You can refer to the implementation of tuple in C++, the number of
which is also unknown.

On Wed, Sep 29, 2021 at 9:17 AM Giorgio Zoppi <giorgio.zo...@gmail.com>
wrote:

> Hello again,
> i am in learning mode. I've seen in the Tablet.java an array of Object[]
> and i want to know the rational of this. We know that in Java generics are
> "fake" due to the type erasure, but is there any possibility to replace
> that:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *** deviceId of this tablet */  public String prefixPath;  /** the list of
> measurement schemas for creating the tablet */  private
> List<IMeasurementSchema> schemas;  /**
> measurementId->indexOf(measurementSchema) */  private Map<String, Integer>
> measurementIndex;  /** timestamps in this tablet */  public long[]
> timestamps;  /** each object is a primitive type array, which represents
> values of one measurement */  public Object[] values;  /** each bitmap
> represents the existence of each value in the current column. */  public
> BitMap[] bitMaps;  /** the number of rows to include in this tablet */
> public int rowSize;  /** the maximum number of rows for this tablet */
> private int maxRowNumber;  /** whether this tablet store data of aligned
> timeseries or not */  private boolean isAligned;*
>
>
> With restrictions, i mean a primitive type array  wrapper that it doesn't
> accept virtually everything
> in
> - addValue(String measurementId, int rowIndex, Object value)
>
>
> And replacing addValue with something like
>
> -addValue<T extends Number> ( String measurementId, int rowIndex, T
> Object);
> -addValue<T extends String> ( String measurementId, int rowIndex, T
> Object);
>
> In this way we could have in the tablet only the 'primitive" types and
> using boxing as well.
> What do you think?
> Best Regards,
> Giorgio.
>
>
>
>
>
> --
> Life is a chess game - Anonymous.
>

Reply via email to