Accessing Remote Objects
To access data from specific objects of a remote system (remote objects), SAP HANA implements virtual tables. Virtual tables are catalog objects, and they are located in a schema.
A virtual table gives access to one remote object (a table or a view in the example below).
Note
Here we deliberately call artifacts on the remote system "objects", and not "tables", for at least two reasons:- First, the type of remote artifacts depends on the remote system. In a database system, of course, these could be tables. But in a file system, there are no tables, but files. A
.csv
or.txt
file with a well-defined structure can most certainly be converted into a virtual table, but this depends on the capability of the adapter and requires a metadata definition to identify column types, among others. - Besides, even in a remote database system, there are classically tables and views. Most of the adapters can access remote tables and remote views in a similar way.
Once virtual tables are created, they can be consumed by the database processes as if they were physically located in the target database. However, the key principle of virtual tables is that they don’t store the data on the local database, but only metadata. Instead, they expose remote data through their supporting remote source whenever a query is executed on top of them.
Note
An alternative approach is possible, which is to consume remote data without virtual tables. It's called Linked Database, and is available only with Smart Data Access remote sources. The concept, benefits, and limitations are discussed later on.Virtual Table Definition
A virtual table has two parts in its definitions:
- The virtual table identifier
- The remote object identifier, including the reference to the remote source
Note
The name of the remote database can be<NULL>
even if the remote system IS indeed a database. This is just because in some configurations, for example with SAP HANA as the remote system, the remote source object already determines the database with the host and port.With other remote system types, a single remote source might reference a database server in which several databases can be reached. This is where the remote database setting is needed in a virtual table definition.
Security Consideration for Virtual Tables
When creating virtual tables, you need to fulfill a number of prerequisites regarding not only the availability of the remote source and remote system, but also the authorizations in place in both systems. Here they are.
On the Local System
To create a virtual table, the prerequisites for the local user are as follows:
- The local user who created the remote source is automatically granted the privilege to create virtual tables on this remote source.
- Any other use requires the CREATE VIRTUAL TABLE privilege on the remote source.
- In any case, the local user needs CREATE ANY privileges on the schema where the virtual table will be stored.
On the Remote System
The credentials configuration of the remote source (or an existing secondary credential for your user on that remote source) determines which remote user is accessing the remote/source object.
Caution
If no credentials at all exist for the remote source (either technical user or secondary credentials), no access is possible to the remote objects. This can be worked around for some types of remote sources, but generally not recommended.As a general rule, when you create a virtual table pointing to a remote database system, the remote user derived from the remote source definition (or an existing secondary credential associated to your user) only needs theCATALOG READprivilege (SAP HANA) or an equivalent, but NOT necessarily a SELECT privilege on the remote table or view (or its containing schema).
Note
This allows for a convenient security configuration when using secondary credentials; indeed, a user with no more than theCATALOG READ
privilege (or equivalent) can create virtual tables without being able to select the data of the corresponding source objects.How to Create a Virtual Table?
A virtual table can be created in two different ways:
- From the SAP HANA Database Explorer, using the catalog
- With an SQL statement