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
48 changes: 40 additions & 8 deletions bi-connectors/PowerBIConnector/SqlOdbcPBIConnector.pq
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@ SqlOdbcPBIConnectorType = 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 to.",
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
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"
];

SqlOdbcPBIConnectorImpl = (Server as text) as table =>
SqlOdbcPBIConnectorImpl = (Server as text, Port as number, UseSSL as logical) as table =>
let
Credential = Extension.CurrentCredential(),
AuthenticationMode = Credential[AuthenticationKind],
Expand Down Expand Up @@ -56,9 +66,29 @@ SqlOdbcPBIConnectorImpl = (Server as text) as table =>
UseSSL = 0
],

// Substract the server from the user input in case if it entered like 'http://localhost' or 'https://srv.com:100500' or 'localhost:0'
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
ServerWithoutPrefix =
kylepbit marked this conversation as resolved.
Show resolved Hide resolved
if Text.StartsWith(Server, "http://") then
Text.RemoveRange(Server, 0, 7)
else if Text.StartsWith(Server, "https://") then
Text.RemoveRange(Server, 0, 8)
else
Server,
ServerWithouPrefixAndPort =
if List.Count(Text.Split(ServerWithoutPrefix, ":")) > 1 then
Text.Split(ServerWithoutPrefix, ":"){0}
else
ServerWithoutPrefix,
// And build the proper string on our own
FinalServerString =
if UseSSL then
"https://" & ServerWithouPrefixAndPort & ":" & Text.From(Port)
else
"http://" & ServerWithouPrefixAndPort & ":" & Text.From(Port),

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

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

// Authentication modes
Authentication = [
Expand All @@ -186,10 +218,10 @@ SqlOdbcPBIConnector = [
// PBIDS Handler
DSRHandlers = [
#"sqlodbc" = [
GetDSR = (server, schema, object, optional options) => [ protocol = "sqlodbc", address = [ server = server ] ],
GetFormula = (dsr, optional options) => () =>
GetDSR = (server, schema, object, optional options) => [ protocol = "sqlodbc", address = [ server = server, port = schema, useSSL = object ] ],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does port = schema?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered that port and useSSL are passed as the second and third arguments.
I'm not sure whether we can rename function arguments, so I kept it as is. I agree it is weird.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can, have you tried to see if it still works?

GetFormula = (dsr, optional options) => () =>
let
db = SqlOdbcPBIConnector.Contents(dsr[address][server])
db = SqlOdbcPBIConnector.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/SqlOdbcPBIConnector.query.pq
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ section SqlOdbcPBIConnector.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 = SqlOdbcPBIConnector.Contents(Host),
Source = SqlOdbcPBIConnector.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 = SqlOdbcPBIConnector.Contents(Host),
Source = SqlOdbcPBIConnector.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
Binary file modified sql-odbc/docs/user/img/pbi_connection_string_options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -34,7 +34,7 @@

<img src="img/pbi_third_party_warning.png" width="500">

* Enter server value. Click on **OK**.
* Enter server address, port and select SSL mode. Click on **OK**.

<img src="img/pbi_connection_string_options.png" width="500">

Expand Down