Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build server address string as of AOS-248 #16

Merged
35 changes: 27 additions & 8 deletions bi-connectors/PowerBIConnector/OpenSearch.pq
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,24 @@ OpenSearchType = type function (
Server as (type text meta [
Documentation.FieldCaption = "Server",
Documentation.FieldDescription = "The hostname of the OpenSearch server.",
Documentation.SampleValues = { "localhost:9200" }
Documentation.SampleValues = { "localhost" }
]),
Port as (type number meta [
Documentation.FieldCaption = "Port",
Documentation.FieldDescription = "Port which OpenSearch server listens on.",
Documentation.SampleValues = { 9200 }
]),
UseSSL as (type logical meta [
Documentation.FieldCaption = "Use SSL",
Documentation.FieldDescription = "Use SSL",
Documentation.AllowedValues = { true, false }
])
)
as table meta [
Documentation.Name = "OpenSearch"
];

OpenSearchImpl = (Server as text) as table =>
OpenSearchImpl = (Server as text, Port as number, UseSSL as logical) as table =>
let
Credential = Extension.CurrentCredential(),
AuthenticationMode = Credential[AuthenticationKind],
Expand Down Expand Up @@ -57,9 +67,16 @@ OpenSearchImpl = (Server as text) as table =>
UseSSL = 0
],

// Subtract the server from the user input in case it's entered like 'http://localhost' or 'https://srv.com:100500' or 'localhost:0'
// And build the proper string on our own
FinalServerString = if UseSSL then
"https://" & Uri.Parts(Server)[Host] & ":" & Text.From(Port)
else
"http://" & Uri.Parts(Server)[Host] & ":" & Text.From(Port),

ConnectionString = [
Driver = "OpenSearch SQL ODBC Driver",
Host = Server
Host = FinalServerString
],

SQLGetInfo = Diagnostics.LogValue("SQLGetInfo_Options", [
Expand Down Expand Up @@ -166,9 +183,11 @@ OpenSearch = [
TestConnection = (dataSourcePath) =>
let
json = Json.Document(dataSourcePath),
Server = json[Server]
Server = json[Server],
Port = json[Port],
UseSSL = json[UseSSL]
in
{ "OpenSearch.Contents", Server },
{ "OpenSearch.Contents", Server, Port, UseSSL },

// Authentication modes
Authentication = [
Expand All @@ -187,10 +206,10 @@ OpenSearch = [
// PBIDS Handler
DSRHandlers = [
#"opensearch-sql" = [
GetDSR = (server, schema, object, optional options) => [ protocol = "opensearch-sql", address = [ server = server ] ],
GetFormula = (dsr, optional options) => () =>
GetDSR = (server, schema, object, optional options) => [ protocol = "opensearch-sql", address = [ server = server, port = schema, useSSL = object ] ],
GetFormula = (dsr, optional options) => () =>
let
db = OpenSearch.Contents(dsr[address][server])
db = OpenSearch.Contents(dsr[address][server], dsr[address][port], dsr[address][useSSL])
in
db,
GetFriendlyName = (dsr) => "OpenSearch SQL ODBC"
Expand Down
8 changes: 5 additions & 3 deletions bi-connectors/PowerBIConnector/OpenSearch.query.pq
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ section OpenSearch.UnitTests;
shared MyExtension.UnitTest =
[
// Common variables for all tests
Host = "localhost:9200",
Host = "localhost",
Port = 9200,
UseSSL = false,

facts =
{
Fact("Connection Test",
7,
let
Source = OpenSearch.Contents(Host),
Source = OpenSearch.Contents(Host, Port, UseSSL),
no_of_columns = Table.ColumnCount(Source)
in
no_of_columns
Expand All @@ -20,7 +22,7 @@ shared MyExtension.UnitTest =
#table(type table [bool0 = logical],
{ {null}, {false}, {true} }),
let
Source = OpenSearch.Contents(Host),
Source = OpenSearch.Contents(Host, Port, UseSSL),
calcs_null_null = Source{[Item="calcs",Schema=null,Catalog=null]}[Data],
grouped = Table.Group(calcs_null_null, {"bool0"}, {})
in
Expand Down
2 changes: 1 addition & 1 deletion sql-odbc/docs/user/power_bi_support.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Connecting OpenSearch to Microsoft Power BI Desktop
# Connecting OpenSearch to Microsoft Power BI Desktop

## Prerequisites
* Microsoft Power BI Desktop
Expand Down