Skip to content

Commit

Permalink
SHOW CATALOGS documentation and integ tests
Browse files Browse the repository at this point in the history
Signed-off-by: Vamsi Manohar <reddyvam@amazon.com>
  • Loading branch information
vamsimanohar committed Oct 27, 2022
1 parent ccc2230 commit d513fc5
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/category.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"user/ppl/cmd/ad.rst",
"user/ppl/cmd/dedup.rst",
"user/ppl/cmd/describe.rst",
"user/ppl/cmd/showcatalogs.rst",
"user/ppl/cmd/eval.rst",
"user/ppl/cmd/fields.rst",
"user/ppl/cmd/grok.rst",
Expand Down
36 changes: 36 additions & 0 deletions docs/user/ppl/cmd/showcatalogs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
=============
show catalogs
=============

.. rubric:: Table of contents

.. contents::
:local:
:depth: 2


Description
============
| Using ``show catalogs`` command to query catalogs configured in the PPL engine. ``show catalogs`` command could be only used as the first command in the PPL query.

Syntax
============
show catalogs


Example 1: Fetch all PROMETHEUS catalogs
=================================

The example fetches all the catalogs configured.

PPL query for all PROMETHEUS CATALOGS::

os> show catalogs | where CONNECTOR_TYPE='PROMETHEUS';
fetched rows / total rows = 1/1
+----------------+------------------+
| CATALOG_NAME | CONNECTOR_TYPE |
|----------------+------------------|
| prometheus | PROMETHEUS |
+----------------+------------------+

2 changes: 2 additions & 0 deletions docs/user/ppl/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ The query start with search command and then flowing a set of command delimited

- `describe command <cmd/describe.rst>`_

- `show catalogs command <cmd/showcatalogs.rst>`_

- `eval command <cmd/eval.rst>`_

- `fields command <cmd/fields.rst>`_
Expand Down
9 changes: 6 additions & 3 deletions doctest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ task doctest(type: Exec, dependsOn: ['bootstrap']) {
}
}

task stopOpenSearch(type: KillProcessTask) {
task stopOpenSearch(type: KillProcessTask)

finalizedBy {
task stopPrometheus() {

doLast {
def pidFile = new File(path, ".prom.pid.lock")
if(!pidFile.exists()) {
logger.quiet "No Prometheus server running!"
Expand All @@ -79,13 +81,14 @@ task stopOpenSearch(type: KillProcessTask) {
} finally {
pidFile.delete()
}
println("Killed Prometheus")
}
}

stopPrometheus.mustRunAfter startPrometheus
doctest.dependsOn startOpenSearch
startOpenSearch.dependsOn startPrometheus
doctest.finalizedBy stopOpenSearch
stopOpenSearch.finalizedBy stopPrometheus
build.dependsOn doctest
clean.dependsOn(cleanBootstrap)

Expand Down
30 changes: 30 additions & 0 deletions integ-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask

import java.util.concurrent.Callable

plugins {
id "de.undercouch.download" version "5.3.0"
}

apply plugin: 'opensearch.build'
apply plugin: 'opensearch.rest-test'
apply plugin: 'java'
apply plugin: 'io.freefair.lombok'
apply plugin: 'com.wiredforcode.spawn'


ext {
projectSubstitutions = [:]
Expand Down Expand Up @@ -101,11 +106,36 @@ testClusters.all {

testClusters.integTest {
plugin ":opensearch-sql-plugin"
keystore 'plugins.query.federation.catalog.config', new File("$projectDir/src/test/resources/catalog/", 'catalog.json')
}
task startPrometheus(type: SpawnProcessTask) {
doFirst {
download.run {
src 'https://github.com/prometheus/prometheus/releases/download/v2.39.1/prometheus-2.39.1.linux-amd64.tar.gz'
dest new File("$projectDir/bin", 'prometheus.tar.gz')
}
copy {
from tarTree("$projectDir/bin/prometheus.tar.gz")
into "$projectDir/bin"
}
copy {
from "$projectDir/bin/prometheus.yml"
into "$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus"
}
}
command "$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus --storage.tsdb.path=$projectDir/bin/prometheus-2.39.1.linux-amd64/data --config.file=$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus.yml"
ready 'TSDB started'
}

task stopPrometheus(type: KillProcessTask)

stopPrometheus.mustRunAfter startPrometheus

// Run PPL ITs and new, legacy and comparison SQL ITs with new SQL engine enabled
integTest {
dependsOn ':opensearch-sql-plugin:bundlePlugin'
dependsOn startPrometheus
finalizedBy stopPrometheus

systemProperty 'tests.security.manager', 'false'
systemProperty('project.root', project.projectDir.absolutePath)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* * Copyright OpenSearch Contributors
* * SPDX-License-Identifier: Apache-2.0
*
*/

package org.opensearch.sql.ppl;

import static org.opensearch.sql.util.MatcherUtils.columnName;
import static org.opensearch.sql.util.MatcherUtils.rows;
import static org.opensearch.sql.util.MatcherUtils.verifyColumn;
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;

import java.io.IOException;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;

public class ShowCatalogsCommandIT extends PPLIntegTestCase {

@Test
public void testShowCatalogsCommands() throws IOException {
JSONObject result = executeQuery("show catalogs");
verifyDataRows(result,
rows("prometheus", "PROMETHEUS"),
rows(".opensearch", "OPENSEARCH"));
verifyColumn(
result,
columnName("CATALOG_NAME"),
columnName("CONNECTOR_TYPE")
);
}

@Test
public void testShowCatalogsCommandsWithWhereClause() throws IOException {
JSONObject result = executeQuery("show catalogs | where CONNECTOR_TYPE='PROMETHEUS'");
verifyDataRows(result,
rows("prometheus", "PROMETHEUS"));
verifyColumn(
result,
columnName("CATALOG_NAME"),
columnName("CONNECTOR_TYPE")
);
}

}
7 changes: 7 additions & 0 deletions integ-test/src/test/resources/catalog/catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"name" : "prometheus",
"connector": "prometheus",
"uri" : "http://localhost:9090"
}
]

0 comments on commit d513fc5

Please sign in to comment.