Query Ocient
Understanding Data Types

Array, Tuple, and Matrix Overview

Arrays, tuples, and matrix data types are complex data types in the

 System.

Arrays

The array data type is a one-dimensional list of values with the same data type. This type enables the support of a one-to-many relationship without creating another table. You create secondary indexes on arrays, which index the elements of the array. For details about secondary indexes, see Secondary Indexes.

Key features:

  • Variable size.
  • Can contain many elements.
  • Indexing into the array starts at 1.
  • Invalid access of the array returns NULL.

For semi-structured data in JSON format, you can express the JSON multi-value column in an array data type. Traditionally in the normalized relational data model, the database represents such data types as a separate table. Each row stores the value of the primary key of the record in the parent table. Therefore, the entity relationship between the tables is always one-to-many, which can result in billions of rows. The array data type eliminates the child tables, which helps reduce the storage footprint and avoids the additional JOIN operations.

Examples

Create a one-dimensional integer array [1, 2, 3] using the sys.dummy virtual table.

SQL


Output

Text


Create a two-dimensional integer array [[1, 2, 3], [4, 5, 6]].

SQL


Output

Text


You can get the same result by casting the array and integers explictly.

SQL


For more examples, see Array Functions and Operators.

Tuples

The tuple data type is a row. This type is a fixed-sized collection of heterogeneous values. Tuples support more complex recursive computational functions. The memory structure of the tuple is identical to the memory structure of the array type. The only difference is that each entry in a tuple can be any type, so the Ocient System can simultaneously store both fixed and variable-sized values in a tuple.

Examples

Create a tuple with fixed-size types. In this case, use three integers.

SQL


Output

Text


You can get the same result by using the tuple type constructor.

SQL


Create a tuple with variable-size types. In this case, use a one-dimensional and two-dimensional array.

SQL


Output

Text


Create a tuple with different types. In this case, an integer, string, and array of integers.

SQL


Output

Text


For more examples, see Tuple Functions and Operators.

Matrixes

A matrix is a fixed-size two-dimensional array of DOUBLE values. A matrix can be a row vector (1xN matrix) or column vector (Nx1 matrix).

Matrixes support machine learning model calculations. For details, see Machine Learning in Ocient.

Examples

Create a 1x4 matrix with numbers 1 through 4 using the make_matrix function that expects values in row-major order. The first two arguments indicate the dimensions of the matrix, and the remaining arguments specify the values for the matrix.

SQL


Output

Text


Create a 2x3 matrix with numbers 1 through 6.

SQL


Output

Text


Create a row vector with four doubles.

SQL


Output

Text


For more examples, see Matrix Functions and Operators.

Related Links