# US 11,120,019 B2 · Adapting a relational query to accommodate hierarchical data

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 11,120,019 B2
- Document ID: US11120019B2
- Status: Granted
- Kind: B2
- Application number: 16/402,224
- Filed: 2019-05-02
- Published: 2019-08-22
- Granted: 2021-09-14
- Earliest claimed: 2014-06-09
- Assignees: International Business Machines Corporation
- Applicants: International Business Machines Corporation
- Inventors: Suavi A. Demir
- Web page: https://patentgrep.com/patent/US11120019B2

## CPC

- G06F 16/24534: {Query rewriting; Transformation}
- G06F 16/2282: {Tablespace storage structures; Management thereof}
- G06F 16/2452: Query translation
- G06F 16/24535: {of sub-queries or views}
- G06F 16/282: {Hierarchical databases, e.g. IMS, LDAP data stores or Lotus Notes}
- G06F 16/284: {Relational databases}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A method, system and computer program product for processing hierarchical data is provided. A method for processing hierarchical data in a relational database includes receiving an input parameter in an initial query for querying an array in a hierarchical data object stored in a table of a relational database, and transforming the initial query into a transformed query configured to place all elements of the array into a different table and to apply a sub-query against the table for the input parameter. Once transformed, predicate evaluation logic of a relational engine of the relational database is applied to the transformed query that is then mapped to the initial query. Finally, responsive to receiving a subsequent instance of the initial query, the mapping is referred to in order to replace the initial query with the transformed query and to subsequently apply the predicate evaluation logic to the transformed query.

## Claims

### Claim 1

A method for processing hierarchical data in a relational database comprising:
receiving from an end user an input parameter in an initial query for querying an array in a hierarchical data object stored in a table of a relational database, the initial query requesting an extraction of a specific array element in the array;
transforming the initial query into a transformed query configured to extract all elements of the array into a different table and to apply a sub-query against the table for the input parameter;
applying predicate evaluation logic of a relational engine of the relational database to the transformed query, the application producing a result set for presentation to the end user;
mapping the transformed query to the initial query such that a subsequent invocation of the initial query is replaced with the transformed query and applied by the relational engine; and,
responsive to receiving a subsequent instance of the initial query, optimizing query performance for the subsequent instance of the initial query by referring to the mapping to replace the initial query with the transformed query and subsequently applying the predicate evaluation logic of the relational engine to the transformed query without requiring a new transformation of the initial query.

### Claim 2 (depends on 1)

The method of claim 1, wherein the hierarchical data object is a Javascript Object Notation (JSON) object.

### Claim 3 (depends on 1)

The method of claim 1, wherein the initial query and the transformed query are structured query language (SQL) queries.

### Claim 4 (depends on 1)

The method of claim 1, further comprising:
explicitly typecasting the elements of the array to a specified data type; and,
responsive to detecting a failure of the typecasting, returning a NULL value to the relational engine.

### Claim 5 (depends on 4)

The method of claim 4, wherein the specified data type is an integer data type.

### Claim 6

A relational database data processing system comprising:
a host computing system comprising at least one computer with memory and at least one processor;
fixed storage disposed in the host computing system;
a relational database stored in the fixed storage, the relational database storing a plurality of hierarchical data objects;
a relational engine executing in the memory of the host computing system and managing queries upon the hierarchical data objects of the relational database; and,
a hierarchical data processing module coupled to the relational engine, the module comprising program code enabled upon execution in the memory of the host computing system to receive from an end user an input parameter in an initial query for querying an array in a hierarchical data object stored in a table of a relational database, the initial query requesting an extraction of a specific array element in the array, to transform the initial query into a transformed query configured to extract all elements of the array into a different table and to apply a sub-query against the table for the input parameter, to direct the relational engine to apply predicate evaluation logic of a relational engine of the relational database to the transformed query, the application producing a result set for presentation to the end user, to map the transformed query to the initial query such that a subsequent invocation of the initial query is replaced with the transformed query and applied by the relational engine, and to respond to receiving a subsequent instance of the initial query, by optimizing query performance for the subsequent instance of the initial query by referring to the mapping to replace the initial query with the transformed query and subsequently applying the predicate evaluation logic of the relational engine to the transformed query without requiring a new transformation of the initial query.

### Claim 7 (depends on 6)

The system of claim 6, wherein the hierarchical data object is a Javascript Object Notation (JSON) object.

### Claim 8 (depends on 6)

The system of claim 6, wherein the initial query and the transformed query are structured query language (SQL) queries.

### Claim 9 (depends on 6)

The system of claim 6, wherein the program code of the module is further enabled to explicitly typecast the elements of the array to a specified data type and to respond to detecting a failure of the typecasting, by returning a NULL value to the relational engine.

### Claim 10 (depends on 9)

The system of claim 9, wherein the specified data type is an integer data type.

### Claim 11

A computer program product for processing hierarchical data in a relational database, the computer program product comprising a computer readable storage medium having program instructions embodied therewith, the program instructions executable by a device to cause the device to perform a method comprising:
receiving, by a device, from an end user an input parameter in an initial query for querying an array in a hierarchical data object stored in a table of a relational database, the initial query requesting an extraction of a specific array element in the array;
transforming, by the device, the initial query into a transformed query configured to extract all elements of the array into a different table and to apply a sub-query against the table for the input parameter;
applying, by the device, predicate evaluation logic of a relational engine of the relational database to the transformed query, the application producing a result set for presentation to the end user;
mapping, by the device, the transformed query to the initial query such that a subsequent invocation of the initial query is replaced with the transformed query and applied by the relational engine; and,
responsive to receiving a subsequent instance of the initial query, optimizing query performance for the subsequent instance of the initial query by referring, by the device, to the mapping to replace the initial query with the transformed query and subsequently applying the predicate evaluation logic of the relational engine to the transformed query without requiring a new transformation of the initial query.

### Claim 12 (depends on 11)

The computer program product of claim 11, wherein the hierarchical data object is a Javascript Object Notation (JSON) object.

### Claim 13 (depends on 11)

The computer program product of claim 11, wherein the initial query and the transformed query are structured query language (SQL) queries.

### Claim 14 (depends on 11)

The computer program product of claim 11, further comprising:
explicitly typecasting, by the device, the elements of the array to a specified data type; and,
responsive to detecting a failure of the typecasting, returning, by the device, a NULL value to the relational engine.

### Claim 15 (depends on 14)

The computer program product of claim 14, wherein the specified data type is an integer data type.
