Open dai-chen opened 1 year ago
An idea for PPL use in Mid Level Option: JDBC API over Transport:
var properties = new Properties();
properties.setProperty("user", "looser");
properties.setProperty("password", "123");
properties.setProperty("lang", "PPL"); // <- The trick happens here
// Open connection
try (Connection conn = DriverManager.getConnection(
"jdbc:opensearch://http://localhost:9200", properties)) {
// Query metadata
Statement stmt = conn.createStatement();
// Query data
List<ADResult> adResults = new ArrayList<>();
ResultSet rs = stmt.executeQuery("search source=<index> | ... <rest PPL query>");
while (rs.hasNext()) {
ADResult result = new AdResult();
result.setId(rs.getInt("ad_id");
...
adResults.add(result);
}
}
Coming from the Alerting plugin perspective, I believe the option, High Level Option: Query DSL over Transport
, seems the best for other plugins to utilize the SQL and PPL query support. This allows plugin to not require in depth knowledge of SQL and PPL and lets the experts (the SQL plugin) deal with the lower level implementations.
The JDBC driver option and the low level option don't seem good coming from a consuming plugin perspective since they require a fair amount of duplicated setup work as well as detailed knowledge on how to use SQL queries. This logic should be ideally abstracted away from this query work and let plugins focus on their plugin features. Also by abstracting it to a high level design, the SQL plugin can ensure the right practices are enforced when doing SQL/PPL queries.
Overview
Background
Requirements
Design: Query Interface
This section discuss the following design options for user query interface.
Low Level Option: Native Transport API
First option is to just follow the convention and add transport API classes to OpenSearch
common-utils
module. This is also what current PPL transport API looks like.Mid Level Option: JDBC API over Transport
One option on higher level is to leverage JDBC API:
Mid Level Option: Transport API with Data Modeling
Alternatively, we can provide thin wrapper on top of transport API and take care of de-serialization work by some data model class.
common-utils
and change whenever API or data model changesHigh Level Option: Query DSL over Transport
Similarly as JOOQ, LINQ and other query DSL library, we can provide higher level query API than aforementioned options.
common-utils
moduleDesign: Permission Control on SQL Transport Action
As new transport action added, new action permission is required correspondingly. Here is an example from @penghuo that shows what's required from user side after SQL transport added:
Alternatively, user can create permission group for the new action permission as below:
Questions: What' the impact on existing user who upgrade to latest version? Is it possible to avoid this and make user unaware?