Automatic Schema Discovery
The adapter automatically infers a relational schema by inspecting a Cassandra object. You can use the RowScanDepth property to define the number of rows the driver will scan to do so. The adapter models all top-level native properties of a collection as columns of an appropriate type.
For example, consider the following JSON representation of a Cassandra object that contains nested structures:
{
id: 12,
name: "Lohia Manufacturers Inc.",
address: {street: "Main Street", city: "Chapel Hill", state: "NC"},
offices: ["Chapel Hill", "London", "New York"]
annual_revenue: 35,600,000
}
The inferred types of the following JSON string are shown below.
Column Name | Data Type | Example Value |
id | Integer | 12 |
name | String | Lohia Manufacturers Inc. |
address | String | {street: "Main Street", city: "Chapel Hill", state: "NC"} |
offices | String | ["Chapel Hill", "London", "New York"] |
annual_revenue | Double | 35,600,000 |
The columns identified during the discovery process also depend on the FlattenArrays and FlattenObjects properties. If FlattenObjects is set, all nested objects will be flattened into a series of columns. The preceding example will be represented by the following columns:
Column Name | Data Type | Example Value |
id | Integer | 12 |
name | String | Lohia Manufacturers Inc. |
address_street | String | Main Street |
address_city | String | Chapel Hill |
address_state | String | NC |
offices | String | ["Chapel Hill", "London", "New York"] |
annual_revenue | Double | 35,600,000 |
The FlattenArrays property can be used to flatten array values into columns of their own. This is only recommended for arrays that are expected to be short, for example the coordinates below:
"coord": [ -73.856077, 40.848447 ]
The FlattenArrays property can be set to 2 to represent the array above as follows:
Column Name | Data Type | Example Value |
coord_0 | Float | -73.856077 |
coord_1 | Float | 40.848447 |
It is best to leave other unbounded arrays as they are and piece out the data for them as needed using JSON Functions.