Skip to content

Business intelligence made simple

Started more adapter tests [skip ci]

Andrew Kane87de56cd696e
diff --git a/Gemfile b/Gemfile
index a49a4671..a6054297 100644
--- a/Gemfile
+++ b/Gemfile
@@ -10,9 +10,27 @@ gem "pg"
gem "sprockets-rails"
# data sources
-gem "elasticsearch"
-gem "mysql2"
-gem "sqlite3"
+# gem "activerecord6-redshift-adapter"
+# gem "aws-sdk-athena"
+# gem "aws-sdk-glue"
+# gem "cassandra-driver"
+# gem "sorted_set"
+# gem "drill-sergeant"
+# gem "elasticsearch"
+# gem "google-cloud-bigquery"
+# gem "hexspace"
+# gem "ignite-client"
+# gem "influxdb"
+# gem "mongo"
+# gem "mysql2"
+# gem "neo4j-core"
+# gem "odbc_adapter"
+# gem "opensearch-ruby"
+# gem "presto-client"
+# gem "restforce"
+# gem "sqlite3"
+# gem "tiny_tds"
+# gem "activerecord-sqlserver-adapter"
# anomaly detection and forecasting
gem "anomaly_detection" if ENV["TEST_ANOMALY_DETECTION"]
diff --git a/lib/blazer/adapters/druid_adapter.rb b/lib/blazer/adapters/druid_adapter.rb
index 736c9900..a99e6619 100644
--- a/lib/blazer/adapters/druid_adapter.rb
+++ b/lib/blazer/adapters/druid_adapter.rb
@@ -4,6 +4,10 @@ module Blazer
TIMESTAMP_REGEX = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\z/
def run_statement(statement, comment)
+ require "json"
+ require "net/http"
+ require "uri"
+
columns = []
rows = []
error = nil
diff --git a/test/adapters/athena_test.rb b/test/adapters/athena_test.rb
new file mode 100644
index 00000000..24939475
--- /dev/null
+++ b/test/adapters/athena_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class AthenaTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "athena"
+ end
+end
diff --git a/test/adapters/bigquery_test.rb b/test/adapters/bigquery_test.rb
new file mode 100644
index 00000000..a17c4868
--- /dev/null
+++ b/test/adapters/bigquery_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class BigqueryTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "bigquery"
+ end
+end
diff --git a/test/adapters/cassandra_test.rb b/test/adapters/cassandra_test.rb
new file mode 100644
index 00000000..cc3c0729
--- /dev/null
+++ b/test/adapters/cassandra_test.rb
@@ -0,0 +1,12 @@
+require_relative "../test_helper"
+
+# CREATE KEYSPACE blazer_test
+# WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
+
+class CassandraTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "cassandra"
+ end
+end
diff --git a/test/adapters/drill_test.rb b/test/adapters/drill_test.rb
new file mode 100644
index 00000000..2132a8e4
--- /dev/null
+++ b/test/adapters/drill_test.rb
@@ -0,0 +1,13 @@
+require_relative "../test_helper"
+
+class DrillTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "drill"
+ end
+
+ def test_run
+ assert_result [{"hello" => "world"}], "SELECT 'world' AS hello"
+ end
+end
diff --git a/test/adapters/druid_test.rb b/test/adapters/druid_test.rb
new file mode 100644
index 00000000..c5471b5f
--- /dev/null
+++ b/test/adapters/druid_test.rb
@@ -0,0 +1,13 @@
+require_relative "../test_helper"
+
+class DruidTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "druid"
+ end
+
+ def test_run
+ assert_result [{"hello" => "world"}], "SELECT 'world' AS hello"
+ end
+end
diff --git a/test/adapters/elasticsearch_test.rb b/test/adapters/elasticsearch_test.rb
index 85b9349a..b48fee3b 100644
--- a/test/adapters/elasticsearch_test.rb
+++ b/test/adapters/elasticsearch_test.rb
@@ -1,13 +1,13 @@
require_relative "../test_helper"
class ElasticsearchTest < ActionDispatch::IntegrationTest
- def test_run
- run_query "SELECT 1", data_source: "elasticsearch"
+ include AdapterTest
+
+ def data_source
+ "elasticsearch"
end
- def test_tables
- get blazer.tables_queries_path(data_source: "elasticsearch")
- assert_response :success
- assert_kind_of Array, JSON.parse(response.body)
+ def test_run
+ assert_result [{"hello" => "world"}], "SELECT 'world' AS hello"
end
end
diff --git a/test/adapters/hive_test.rb b/test/adapters/hive_test.rb
new file mode 100644
index 00000000..7c4a882e
--- /dev/null
+++ b/test/adapters/hive_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class HiveTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "hive"
+ end
+end
diff --git a/test/adapters/ignite_test.rb b/test/adapters/ignite_test.rb
new file mode 100644
index 00000000..c3a03bfa
--- /dev/null
+++ b/test/adapters/ignite_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class IgniteTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "ignite"
+ end
+end
diff --git a/test/adapters/influxdb_test.rb b/test/adapters/influxdb_test.rb
new file mode 100644
index 00000000..8ac9ccb9
--- /dev/null
+++ b/test/adapters/influxdb_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class InfluxdbTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "influxdb"
+ end
+end
diff --git a/test/adapters/mongodb_test.rb b/test/adapters/mongodb_test.rb
new file mode 100644
index 00000000..1b08bacc
--- /dev/null
+++ b/test/adapters/mongodb_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class MongodbTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "mongodb"
+ end
+end
diff --git a/test/adapters/mysql_test.rb b/test/adapters/mysql_test.rb
index cb136731..77526267 100644
--- a/test/adapters/mysql_test.rb
+++ b/test/adapters/mysql_test.rb
@@ -1,13 +1,13 @@
require_relative "../test_helper"
class MysqlTest < ActionDispatch::IntegrationTest
- def test_run
- run_query "SELECT 1", data_source: "mysql"
+ include AdapterTest
+
+ def data_source
+ "mysql"
end
- def test_tables
- get blazer.tables_queries_path(data_source: "mysql")
- assert_response :success
- assert_empty JSON.parse(response.body)
+ def test_run
+ assert_result [{"hello" => "world"}], "SELECT 'world' AS hello"
end
end
diff --git a/test/adapters/neo4j_test.rb b/test/adapters/neo4j_test.rb
new file mode 100644
index 00000000..00ae3971
--- /dev/null
+++ b/test/adapters/neo4j_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class Neo4jTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "neo4j"
+ end
+end
diff --git a/test/adapters/opensearch_test.rb b/test/adapters/opensearch_test.rb
new file mode 100644
index 00000000..79ee678b
--- /dev/null
+++ b/test/adapters/opensearch_test.rb
@@ -0,0 +1,13 @@
+require_relative "../test_helper"
+
+class OpensearchTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "opensearch"
+ end
+
+ def test_run
+ assert_result [{"'world'" => "world"}], "SELECT 'world' AS hello"
+ end
+end
diff --git a/test/adapters/postgresql_test.rb b/test/adapters/postgresql_test.rb
new file mode 100644
index 00000000..76600f88
--- /dev/null
+++ b/test/adapters/postgresql_test.rb
@@ -0,0 +1,13 @@
+require_relative "../test_helper"
+
+class PostgresqlTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "postgresql"
+ end
+
+ def test_run
+ assert_result [{"hello" => "world"}], "SELECT 'world' AS hello"
+ end
+end
diff --git a/test/adapters/presto_test.rb b/test/adapters/presto_test.rb
new file mode 100644
index 00000000..03317ee6
--- /dev/null
+++ b/test/adapters/presto_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class PrestoTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "presto"
+ end
+end
diff --git a/test/adapters/redshift_test.rb b/test/adapters/redshift_test.rb
new file mode 100644
index 00000000..77dc6512
--- /dev/null
+++ b/test/adapters/redshift_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class RedshiftTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "redshift"
+ end
+end
diff --git a/test/adapters/salesforce_test.rb b/test/adapters/salesforce_test.rb
new file mode 100644
index 00000000..8c48d781
--- /dev/null
+++ b/test/adapters/salesforce_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class SalesforceTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "salesforce"
+ end
+end
diff --git a/test/adapters/snowflake_test.rb b/test/adapters/snowflake_test.rb
new file mode 100644
index 00000000..705cc6c7
--- /dev/null
+++ b/test/adapters/snowflake_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class SnowflakeTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "snowflake"
+ end
+end
diff --git a/test/adapters/soda_test.rb b/test/adapters/soda_test.rb
new file mode 100644
index 00000000..806ee49a
--- /dev/null
+++ b/test/adapters/soda_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class SodaTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "soda"
+ end
+end
diff --git a/test/adapters/spark_test.rb b/test/adapters/spark_test.rb
new file mode 100644
index 00000000..38ee489c
--- /dev/null
+++ b/test/adapters/spark_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class SparkTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "spark"
+ end
+end
diff --git a/test/adapters/sqlite_test.rb b/test/adapters/sqlite_test.rb
index 24a27a0d..1f71f755 100644
--- a/test/adapters/sqlite_test.rb
+++ b/test/adapters/sqlite_test.rb
@@ -1,13 +1,13 @@
require_relative "../test_helper"
class SqliteTest < ActionDispatch::IntegrationTest
- def test_run
- run_query "SELECT 1", data_source: "sqlite"
+ include AdapterTest
+
+ def data_source
+ "sqlite"
end
- def test_tables
- get blazer.tables_queries_path(data_source: "sqlite")
- assert_response :success
- assert_empty JSON.parse(response.body)
+ def test_run
+ assert_result [{"hello" => "world"}], "SELECT 'world' AS hello"
end
end
diff --git a/test/adapters/sqlserver_test.rb b/test/adapters/sqlserver_test.rb
new file mode 100644
index 00000000..5253fa2e
--- /dev/null
+++ b/test/adapters/sqlserver_test.rb
@@ -0,0 +1,9 @@
+require_relative "../test_helper"
+
+class SqlserverTest < ActionDispatch::IntegrationTest
+ include AdapterTest
+
+ def data_source
+ "sqlserver"
+ end
+end
diff --git a/test/internal/config/blazer.yml b/test/internal/config/blazer.yml
index 6f7700cf..1c36f646 100644
--- a/test/internal/config/blazer.yml
+++ b/test/internal/config/blazer.yml
@@ -33,16 +33,83 @@ data_sources:
# user_id: "SELECT id, name FROM users WHERE id IN {value}"
status: {0: "Active", 1: "Archived"}
+ athena:
+ adapter: athena
+ database: blazer_test
+
+ bigquery:
+ adapter: bigquery
+ project: your-project
+ keyfile: path/to/keyfile.json
+
+ cassandra:
+ url: cassandra://localhost:9042/blazer_test
+
+ drill:
+ adapter: drill
+ url: http://localhost:8047
+
+ druid:
+ adapter: druid
+ url: http://localhost:8082
+
elasticsearch:
adapter: elasticsearch
url: http://localhost:9200
+ hive:
+ adapter: hive
+ url: sasl://localhost:10000/blazer_test
+
+ influxdb:
+ adapter: influxdb
+ url: http://localhost:8086/blazer_test
+
+ mongodb:
+ url: mongodb://localhost:27017/blazer_test
+
mysql:
url: mysql2://localhost:3306/blazer_test
+ neo4j:
+ adapter: neo4j
+ url: http://neo4j:secret@localhost:7474/blazer_test
+
+ opensearch:
+ adapter: opensearch
+ url: http://localhost:9200
+
+ postgresql:
+ url: postgres://localhost/blazer_test
+
+ presto:
+ url: presto://localhost:8080/blazer_test
+
+ redshift:
+ url: redshift://localhost:5439/blazer_test
+
+ salesforce:
+ adapter: salesforce
+
+ soda:
+ adapter: soda
+ # url: https://...
+ # app_token: ...
+
+ spark:
+ adapter: spark
+ url: sasl://localhost:10000/blazer_test
+
+ snowflake:
+ adapter: snowflake
+ # conn_str: ...
+
sqlite:
url: "sqlite3::memory:"
+ sqlserver:
+ url: sqlserver://localhost:1433/blazer_test
+
# create audits
audit: true
diff --git a/test/support/adapter_test.rb b/test/support/adapter_test.rb
new file mode 100644
index 00000000..812618a3
--- /dev/null
+++ b/test/support/adapter_test.rb
@@ -0,0 +1,15 @@
+module AdapterTest
+ def test_tables
+ get blazer.tables_queries_path(data_source: data_source)
+ assert_response :success
+ assert_kind_of Array, JSON.parse(response.body)
+ end
+
+ private
+
+ def assert_result(expected, statement)
+ run_query statement, data_source: data_source, format: "csv"
+ assert_response :success
+ assert_equal expected, CSV.parse(response.body, headers: true).map(&:to_h)
+ end
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index aa461f74..b8d95949 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -29,3 +29,5 @@ class ActionDispatch::IntegrationTest
Blazer::Check.create!(schedule: "5 minutes", **attributes)
end
end
+
+require_relative "support/adapter_test"