Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Concept
Wouldn't it be nice if your database could connect to other systems to use their data ? To do this using SAP HANA Cloud it is possible to use a
virtual table. It functions like aviewon top of atable/viewin aremote source. The underlying functioning of aremote sourceis a specificODBCdriver. One of the more interesting drivers is theODatadriver. Which doesn't use a proprietary database connection, but rather relies onHTTPto fetch the data out of a remote system.With the current
INSERTandUPSERTimplementation beingJSONbased. The obvious next step was to check whetherpostgresandsqlitecould trigger anHTTPrequest. Forsqlitewith the custom functions being simple javascript functions it was clearly possible. Withpostgresthere are a lot of extensions so of course pgsql-http exists.Proof of Concept
First thing we need is the "other" system. Simple
cds exportthe catalog service of the bookshop.Next consume the
data productin the test model.Using the
@data.productannotation it is possible to identify the entities that are located in the "other" system. Making sure to annotate the entities withcds.persistence.existsso that the compiler will expect them to already be deployed. So ensure to make a view which uses theHTTPfunction of the database to download the data.If only it was so simple. All the
JSONfunctions producestringvalues as types have to be consistent. This is where theINSERTlogic comes into play. By looking at theelementsof the entity it is possible to use theinput converterto create the correctSQLdata type out of theJSONstring values. Allowing the database to process the data as if it was provided by a nativeview.You might at this point have started to ask "why ?". As there is also
service level data integrationwhich does pretty much the same thing. Well the@cap-js/cds-dbscan do a lot of advanced features. Which are non trivial to re implement in the javascript layer. Additionally any javascript implementation of these features wouldn't have a "good" performance. It would both cost a lot of CPU cycles and a lot of memory to achieve the same results. AsHANA,postgresandsqliteall are written inC/C++with their primary focus on optimizing relational data manipulation. So when a query has to do awhere,join,group by,order by,path expressionorexpandthe databases have all the optimized tools available in native implementations.So while this is a very simple solution it provides a lot of power. Additionally in the case of
postgresit is possible to take a more robust implementation by using foreign data wrappers. Which comes with the same benefits (and drawbacks) as SAP HANA Cloud remote sources.FYI
In the case of
sqlitethehttpfunction is defined asdeterministic. Depending on the interpretation of the worddeterministicthe function could only be called a single time, but in reality the function will be called once per query. Therefor it is safe to have it defined asdeterministic. With the additional benefit that it will only be called once for an expand instead of once for each row.