diff --git a/bi-connectors/PowerBIConnector/OpenSearch.pq b/bi-connectors/PowerBIConnector/OpenSearch.pq index 9154f331bb..be8fa0ec44 100644 --- a/bi-connectors/PowerBIConnector/OpenSearch.pq +++ b/bi-connectors/PowerBIConnector/OpenSearch.pq @@ -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], @@ -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", [ @@ -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 = [ @@ -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" diff --git a/bi-connectors/PowerBIConnector/OpenSearch.query.pq b/bi-connectors/PowerBIConnector/OpenSearch.query.pq index 3b4d649689..19c84006bf 100644 --- a/bi-connectors/PowerBIConnector/OpenSearch.query.pq +++ b/bi-connectors/PowerBIConnector/OpenSearch.query.pq @@ -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 @@ -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 diff --git a/sql-odbc/docs/user/power_bi_support.md b/sql-odbc/docs/user/power_bi_support.md index c9a00dbab3..be50860deb 100644 --- a/sql-odbc/docs/user/power_bi_support.md +++ b/sql-odbc/docs/user/power_bi_support.md @@ -1,4 +1,4 @@ -# Connecting OpenSearch to Microsoft Power BI Desktop +# Connecting OpenSearch to Microsoft Power BI Desktop ## Prerequisites * Microsoft Power BI Desktop