Blog Series
|
This blog post is part of the ongoing series titled 'Quirky Nuggets.' Within this blog post, we will delve into the world of OData operators and delve into the undeployment of database artifacts using the HDI deployer.
This quirky nugget is about OData operators. In OData, operators are used to perform various operations on data within the context of a query. These operators enable filtering, sorting, and transforming data in OData queries. Some commonly used operators are:
These are some of the operators commonly used in OData queries. The specific set of operators supported may vary depending on the OData service implementation you are working with. Based on this, I have tried some of the operators with OData service of a CAP based application as shown below:
You can utilize the provided schema and service definition as a basis for the examples provided. If you prefer, you can load data into the schema to test them.
db/schema.cds | srv/service.cds |
namespace cap_quirks_03.db; using {cuid} from '@sap/cds/common'; entity Roots : cuid { name : String(20); descr : String(100); dfield : Date; tfield : Time; dtfield : DateTime; tsfield : Timestamp; nfield : Integer; afield : Decimal(20, 6); } | using { cap_quirks_03.db as db } from '../db/schema'; service MyService { entity Roots as projection on db.Roots; } |
Now let's look at some examples:
@Host = {{Host}} GET {{Host}}/my/Roots?$filter=nfield eq floor(789.20) GET {{Host}}/my/Roots?$filter=nfield ge ceiling(700.30) GET {{Host}}/my/Roots?$filter=nfield ge round(800.30) GET {{Host}}/my/Roots?$filter=afield ge 23891100.123 GET {{Host}}/my/Roots?$filter=startswith(name,'root') GET {{Host}}/my/Roots?$filter=startswith(toupper(name),'ROOT') GET {{Host}}/my/Roots?$filter=startswith(tolower(name),tolower('ROOT')) GET {{Host}}/my/Roots?$filter=endswith(name,'1') GET {{Host}}/my/Roots?$filter=contains(name,'ot') GET {{Host}}/my/Roots?$filter=INDEXOF(tolower(name),tolower('Root')) ne -1 GET {{Host}}/my/Roots?$filter=LENGTH(name) gt 5 GET {{Host}}/my/Roots?$filter=substring(name,0,4) eq tolower('Root') GET {{Host}}/my/Roots?$filter=trim(name) eq 'root 1' GET {{Host}}/my/Roots?$filter=concat(name,descr) eq 'root 2descr 2' GET {{Host}}/my/Roots?$filter=year(dfield) eq 2023 GET {{Host}}/my/Roots?$filter=month(dfield) gt 6 GET {{Host}}/my/Roots?$filter=day(dfield) gt 10 GET {{Host}}/my/Roots?$filter=hour(tfield) gt 10 GET {{Host}}/my/Roots?$filter=minute(tfield) gt 15 GET {{Host}}/my/Roots?$filter=second(tfield) gt 15 GET {{Host}}/my/Roots?$filter=day(dtfield) ge 10 and hour(dtfield) ge 10 GET {{Host}}/my/Roots?$filter=fractionalseconds(tsfield) gt 400 GET {{Host}}/my/Roots?$filter=date(dtfield) eq 2023-02-20 GET {{Host}}/my/Roots?$filter=time(dtfield) ge 10:20:20
OData operators enable filtering, sorting, and transforming data in queries, including comparison, logical, arithmetic, string, and date/time operators.
Note: It is essential that proper space is provided in query and unnecessary space will result in erroneous response.
The SAP HDI Deployer (@sap/hdi-deploy) module is a deployment tool provided by SAP to simplify the deployment of db artifacts to SAP HANA databases. It is designed to work with Node.js and provides a command-line interface (CLI) for deploying HDI artifacts, such as database tables, views, and procedures, to a target HANA database instance. The @Sisn/hdi-deploy module abstracts the complexity of the deployment process and automates tasks such as creating database containers, deploying artifacts, and managing dependencies. It is commonly used in SAP HANA development projects to streamline the deployment process and ensure consistent and reliable deployments.
During the development of an application, modifications to the schema or service definitions often lead to corresponding changes in the database tables and views. These changes may involve adding or removing tables and views. In a CAP based application, when the project is built, it generates HANA database artifacts based on the provided schema and service definitions. Normally, the HDI deployer then schedules only the newly added or modified HANA database artifacts for deployment. By default, the deployer does not schedule the removal of deleted artifacts. However, additional configuration options can be implemented in your project to enable automatic undeployment of the deleted artifacts. This nugget will provide you with various configurations to achieve that.
To illustrate the necessary configuration, consider the following schema, which consists of three entities: Roots, CompMItems, and Roots2.
schema.cds
When it becomes necessary to remove the Roots2 entity from the schema definition, it is also essential to delete it from the HDI container in the HANA database. Here are different approaches to achieve this:
cds deploy --to hana:cap_quirks_04-db --auto-undeploy
undeploy.json
[ "src/gen/**/*.hdbview", "src/gen/**/*.hdbindex", "src/gen/**/*.hdbconstraint", "src/gen/cap_quirks_04.db.Roots2.hdbtable" ]Note: "real" paths, path patterns and path negations are supported as shown below:
[ "src/Table.hdbcds", "src/Procedure.hdbprocedure", "src/*.hdbtable", "**/*.hdbtable", "!**/*.hdbtable" ]
First Approach- name: cap_quirks_04-db-deployer type: hdb path: gen/db properties: HDI_DEPLOY_OPTIONS: auto_undeploy: true parameters: buildpack: nodejs_buildpack requires: - name: cap_quirks_04-db |
Second Approach- name: cap_quirks_04-db-deployer type: hdb path: gen/db properties: HDI_DEPLOY_OPTIONS: undeploy: - "src/gen/cap_quirks_04.db.Roots2.hdbtable" parameters: buildpack: nodejs_buildpack requires: - name: cap_quirks_04-db |
Note that, both properties are set under HDI_DEPLOY_OPTIONS and that becomes an user-defined environment variable in cap_quirks_04-db-deployer which is used by HDI deployer to process undeployment.
By applying the provided additional configuration, the HDI Deployer can be utilized to automatically undeploy deleted artifacts.
In this blog post, we explored a bit about OData operators and undeployment of database artifacts using the HDI deployer.
More information about cloud application programming model can be found here. You can follow my profile to get notification of the next blog post on CAP. Please feel free to provide any feedback you have in the comments section below and ask your questions about the topic in sap community using this link.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
10 | |
9 | |
9 | |
8 | |
7 | |
6 | |
6 | |
5 |