Skip to content

Commit

Permalink
Merge branch 'main' into data-source/amazon-athena
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlagunas authored Dec 11, 2024
2 parents 54b6b61 + 8246bb6 commit c96839e
Show file tree
Hide file tree
Showing 13 changed files with 400 additions and 47 deletions.
48 changes: 48 additions & 0 deletions e2e/Sandbox/DashboardCreators/MSAzureSqlServerDSDashboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Reveal.Sdk.Dom;
using Reveal.Sdk.Dom.Data;
using Reveal.Sdk.Dom.Visualizations;
using System.Collections.Generic;

namespace Sandbox.DashboardFactories
{
internal class MSAzureSqlServerDSDashboard : IDashboardCreator
{
public string Name => "MS Azure Sql Server";

public RdashDocument CreateDashboard()
{
var document = new RdashDocument("MS Azure Sql Dashboard");

var msAzureSqlDS = new MicrosoftAzureSqlServerDataSource()
{
Id = "MSAzureSqlId",
Title = "Microsoft Azure Sql Server Data Source",
Subtitle = "MS Azure Sql Server DS Subtitle",
Database = "reveal",
DefaultRefreshRate = "180",
Encrypt = false,
Host = "revealtesting.database.windows.net",
Port = 1433,
TrustServerCertificate = false
};

var msAzureSqlDSItem = new MicrosoftAzureSqlServerDataSourceItem("Microsoft Azure Sql Data Source Item", msAzureSqlDS)
{
Id = "MSAzureSqlItemId",
Title = "Microsoft Azure Sql Server Data Source Item",
Subtitle = "MS Azure Sql Server DSI Subtitle",
Table = "Customers",
Fields = new List<IField>()
{
new TextField("City"),
new TextField("CustomerID"),
}
};

document.Visualizations.Add(new GridVisualization("Customers in France", msAzureSqlDSItem)
.SetColumns("CustomerID", "City"));

return document;
}
}
}
50 changes: 50 additions & 0 deletions e2e/Sandbox/DashboardCreators/SnowFlakeDashboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Reveal.Sdk.Dom;
using Reveal.Sdk.Dom.Data;
using Reveal.Sdk.Dom.Visualizations;
using System.Collections.Generic;

namespace Sandbox.DashboardFactories
{
internal class SnowflakeDashboard : IDashboardCreator
{
public string Name => "Snowflake Data Source";

public RdashDocument CreateDashboard()
{
var snowflakeDS = new SnowflakeDataSource()
{
Id = "SnowflakeDSId",
Title = "Snowflake Data source",
Subtitle = "Snowflake Subtitle",
Account = "pqwkobs-xb90908",
DefaultRefreshRate = "120",
Host = "gpiskyj-al16914.snowflakecomputing.com",
Database = "SNOWFLAKE_SAMPLE_DATA",
Warehouse = "COMPUTE_WH",
Schema = "TPCDS_SF100TCL"
};

var snowflakeDSI = new SnowflakeDataSourceItem("Snowflake DSI Title", snowflakeDS)
{
Id = "SnowflakeDSItemId",
Title = "Snowflake data source Item",
Subtitle = "Snowflake data source Item Subtitle",
Schema = "TPCH_SF10",
Table = "ORDERS",
Database = "SNOWFLAKE_SAMPLE_DATA",
Fields = new List<IField>
{
new NumberField("O_ORDERKEY"),
new NumberField("O_CUSTKEY"),
new TextField("O_ORDERPRIORITY"),
}
};

var document = new RdashDocument("Snowflake Dashboard");

document.Visualizations.Add(new PieChartVisualization("Snowflake Order Priorities", snowflakeDSI)
.SetLabel("O_ORDERPRIORITY").SetValues("O_CUSTKEY"));
return document;
}
}
}
3 changes: 3 additions & 0 deletions e2e/Sandbox/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ public partial class MainWindow : Window
new HealthcareDashboard(),
new ManufacturingDashboard(),
new MarketingDashboard(),
new MSAzureSqlServerDSDashboard(),
new PostgresqlDashboard(),
new RestDataSourceDashboard(),
new SalesDashboard(),
new SnowflakeDashboard(),
new SqlServerDataSourceDashboards(),
};

Expand All @@ -62,6 +64,7 @@ public MainWindow()
RevealSdkSettings.DataSourceProvider = new DataSourceProvider();
RevealSdkSettings.AuthenticationProvider = new AuthenticationProvider();
RevealSdkSettings.DataSources.RegisterMicrosoftSqlServer().RegisterMicrosoftAnalysisServices().RegisterPostgreSQL().RegisterAmazonAthena();
RevealSdkSettings.DataSources.RegisterSnowflake();

LoadDashboards();

Expand Down
14 changes: 12 additions & 2 deletions e2e/Sandbox/Reveal/AuthenticationProvider.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Reveal.Sdk.Data;
using Reveal.Sdk.Data;
using Reveal.Sdk.Data.Amazon.Athena;
using Reveal.Sdk.Data.Amazon.S3;
using Reveal.Sdk.Data;
using Reveal.Sdk.Data.Microsoft.AnalysisServices;
using Reveal.Sdk.Data.Microsoft.SqlServer;
using Reveal.Sdk.Data.Snowflake;
using Reveal.Sdk.Data.PostgreSQL;
using System.Threading.Tasks;

Expand All @@ -13,14 +15,22 @@ internal class AuthenticationProvider : IRVAuthenticationProvider
public Task<IRVDataSourceCredential> ResolveCredentialsAsync(RVDashboardDataSource dataSource)
{
IRVDataSourceCredential userCredential = null;
if (dataSource is RVSqlServerDataSource)
if (dataSource is RVAzureSqlDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential("azure-username", "password");
}
else if (dataSource is RVSqlServerDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential();
}
else if (dataSource is RVNativeAnalysisServicesDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential("username", "password", "domain");
}
else if (dataSource is RVSnowflakeDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential("snow-flake-username", "snow-flake-password");
}
else if (dataSource is RVPostgresDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential("postgres", "postgres");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using Reveal.Sdk.Dom.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Reveal.Sdk.Dom.Data;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems
Expand All @@ -13,7 +9,7 @@ public class MicrosoftAzureSqlServerDataSourceItemFixture
[Theory]
[InlineData("DS Title", "DS Item Title", "DS Title", "DS Item Title")]
[InlineData(null, "DS Item Title", "DS Item Title", "DS Item Title")]
public void Constructor_SetsTitleAndDatasource_AsProvided(string dSTitle, string dSItemTitle, string expectedDSTitle, string expectedDSItemTitle)
public void Constructor_CreateDSItemWithExpectedFields_WithTitleAndMSAzureSqlServerDataSource(string dSTitle, string dSItemTitle, string expectedDSTitle, string expectedDSItemTitle)
{
// Arrange
var dataSource = new MicrosoftAzureSqlServerDataSource() { Title = dSTitle };
Expand All @@ -23,11 +19,89 @@ public void Constructor_SetsTitleAndDatasource_AsProvided(string dSTitle, string

// Assert
Assert.Equal(expectedDSItemTitle, dataSourceItem.Title);
Assert.Equal(dataSource, dataSourceItem.DataSource);
Assert.Equal(dataSource.Id, dataSourceItem.DataSource.Id);
Assert.Equal(dataSource.Id, dataSourceItem.DataSourceId);
Assert.Equal(expectedDSTitle, dataSourceItem.DataSource.Title);
Assert.Equal(dSItemTitle, dataSourceItem.Title);
Assert.Equal(dataSource, dataSourceItem.DataSource);
Assert.Same(dataSource, dataSourceItem.DataSource);
}

[Fact]
public void Constructor_CreateDSItemWithExpectedFields_WithTitle()
{
// Arrange
var expectedDSItemTitle = "Azure SQL DS Item title";

// Act
var dataSourceItem = new MicrosoftAzureSqlServerDataSourceItem(expectedDSItemTitle);

// Assert
Assert.Equal(expectedDSItemTitle, dataSourceItem.Title);
Assert.NotNull(dataSourceItem.DataSource);
Assert.IsType<MicrosoftAzureSqlServerDataSource>(dataSourceItem.DataSource);
Assert.Equal(expectedDSItemTitle, dataSourceItem.DataSource.Title);
}

[Theory]
[InlineData("DS Title", "DS Item Title", "DS Title", "DS Item Title")]
[InlineData(null, "DS Item Title", "DS Item Title", "DS Item Title")]
public void Constructor_CreateDSItemWithExpectedFields_WithTitleAndDataSource(string dSTitle, string dSItemTitle, string expectedDSTitle, string expectedDSItemTitle)
{
// Arrange
var dataSource = new DataSource () { Title = dSTitle };

// Act
var dataSourceItem = new MicrosoftAzureSqlServerDataSourceItem(dSItemTitle, dataSource);

// Assert
Assert.Equal(expectedDSItemTitle, dataSourceItem.Title);
Assert.Equal(dataSource.Id, dataSourceItem.DataSource.Id);
Assert.Equal(dataSource.Id, dataSourceItem.DataSourceId);
Assert.Equal(expectedDSTitle, dataSourceItem.DataSource.Title);
Assert.NotSame(dataSource, dataSourceItem.DataSource);
Assert.IsType<MicrosoftAzureSqlServerDataSource>(dataSourceItem.DataSource);
}

[Fact]
public void ToJsonString_CreateExpectedRevealJson_NoConditions()
{
// Arrange
var expectedJson = @"{
""_type"": ""DataSourceItemType"",
""Id"": ""azureSqlDsItemId"",
""Title"": ""Azure SQL DSItem"",
""Subtitle"": ""Azure SQL DS Item SubTitle"",
""DataSourceId"": ""azureSqlId"",
""HasTabularData"": true,
""HasAsset"": false,
""Properties"": {
""ServerAggregation"": true,
""Database"": ""reveal"",
""Table"": ""Categories""
},
""Parameters"": {}
}";
var dataSource = new MicrosoftAzureSqlServerDataSource()
{
Id = "azureSqlId"
};
var dataSourceItem = new MicrosoftAzureSqlServerDataSourceItem("Azure SQL DSItem", dataSource)
{
Id = "azureSqlDsItemId",
Subtitle = "Azure SQL DS Item SubTitle",
HasTabularData = true,
HasAsset = false,
ProcessDataOnServer = true,
Database = "reveal",
Table = "Categories",
};

// Act
var json = dataSourceItem.ToJsonString();
var expectedJObject = JObject.Parse(expectedJson);
var actualJObject = JObject.Parse(json);

// Assert
Assert.Equal(expectedJObject, actualJObject);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Reveal.Sdk.Dom.Core.Extensions;
using Newtonsoft.Json.Linq;
using Reveal.Sdk.Dom.Core.Constants;
using Reveal.Sdk.Dom.Core.Extensions;
using Reveal.Sdk.Dom.Data;
using Xunit;

Expand All @@ -7,49 +9,103 @@ namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems
public class SnowflakeDataSourceItemFixture
{
[Theory]
[InlineData("Test Item")]
[InlineData(null)]
public void Constructor_SetsTitleAndDataSource_WhenCalled(string title)
[InlineData("DS Title", "DS Title", "DSI Title", "DSI Title")]
[InlineData(null, "DSI Title", "DSI Title", "DSI Title")]
public void Constructor_CreateSnowFlakeDSI_WithTitleAndDataSource(string dsTitle, string expectedDSTitle, string dsiTitle, string expectedDSITitle)
{
// Arrange
var dataSource = new SnowflakeDataSource();
var dataSource = new DataSource() { Title = dsTitle };

// Act
var item = new SnowflakeDataSourceItem(title, dataSource);
var item = new SnowflakeDataSourceItem(dsiTitle, dataSource);

// Assert
Assert.Equal(title, item.Title);
Assert.Equal(dataSource, item.DataSource);
Assert.Equal(SchemaTypeNames.DataSourceItemType, item.SchemaTypeName);
Assert.Equal(expectedDSTitle, item.DataSource.Title);
Assert.Equal(dataSource.Id, item.DataSource.Id);
Assert.Equal(dataSource.Id, item.DataSourceId);
Assert.IsType<SnowflakeDataSource>(item.DataSource);
Assert.NotSame(dataSource, item.DataSource);
Assert.Equal(expectedDSITitle, item.Title);
}

[Theory]
[InlineData("Test Item")]
[InlineData(null)]
public void Constructor_SetsTitleAndDataSource_WhenConstructedWithGenericDataSource(string title)
[InlineData("DS Title", "DS Title", "DSI Title", "DSI Title")]
[InlineData(null, "DSI Title", "DSI Title", "DSI Title")]
public void Constructor_CreateSnowFlakeDSI_WithTitleAndSnowFlakeDataSource(string dsTitle, string expectedDSTitle, string dsiTitle, string expectedDSITitle)
{
// Arrange
var dataSource = new DataSource();
var dataSource = new SnowflakeDataSource() { Title = dsTitle };

// Act
var item = new SnowflakeDataSourceItem(title, dataSource);
var item = new SnowflakeDataSourceItem(dsiTitle, dataSource);

// Assert
Assert.Equal(title, item.Title);
Assert.Equal(SchemaTypeNames.DataSourceItemType, item.SchemaTypeName);
Assert.Equal(expectedDSTitle, item.DataSource.Title);
Assert.Equal(dataSource.Id, item.DataSource.Id);
Assert.Equal(dataSource.Id, item.DataSourceId);
Assert.IsType<SnowflakeDataSource>(item.DataSource);
Assert.Same(dataSource, item.DataSource);
Assert.Equal(expectedDSITitle, item.Title);
}

[Fact]
public void ProcessDataOnServer_ShouldSetAndGetValue_WithInputs()
public void GetProcessDataOnServer_ReturnSameValue_AfterSet()
{
// Arrange
var item = new SnowflakeDataSourceItem("Test Item", new SnowflakeDataSource());
var expectedProcessDataOnServer = true;

// Act
item.ProcessDataOnServer = expectedProcessDataOnServer;

// Assert
Assert.Equal(expectedProcessDataOnServer, item.ProcessDataOnServer);
Assert.Equal(expectedProcessDataOnServer, item.Properties.GetValue<bool>("ServerAggregation"));
}

[Fact]
public void ToJsonString_CreatesFormattedJson_NoConditions()
{
// Arrange
var expectedJson = """
{
"_type": "DataSourceItemType",
"Id": "a60ab508-0ed4-46e4-8d90-c3a9c09c29b8",
"Title": "SnowFlake DSI",
"DataSourceId": "snowflake_ds",
"HasTabularData": true,
"HasAsset": false,
"Properties": {
"ServerAggregation": true,
"Table": "CALL_CENTER",
"Schema": "TPCDS_SF100TCL"
},
"Parameters": {}
}
""";
var dataSource = new SnowflakeDataSource()
{
Id = "snowflake_ds",
};
var dataSourceItem = new SnowflakeDataSourceItem("SnowFlake DSI", dataSource)
{
Id = "a60ab508-0ed4-46e4-8d90-c3a9c09c29b8",
HasTabularData = true,
HasAsset = false,
ProcessDataOnServer = true,
Table = "CALL_CENTER",
Schema = "TPCDS_SF100TCL",
};
var expectedJObject = JObject.Parse(expectedJson);

// Act
item.ProcessDataOnServer = true;
var json = dataSourceItem.ToJsonString();
var actualJObject = JObject.Parse(json);

// Assert
Assert.True(item.ProcessDataOnServer);
Assert.True(item.Properties.GetValue<bool>("ServerAggregation"));
Assert.Equal(expectedJObject, actualJObject);
}
}
}
Loading

0 comments on commit c96839e

Please sign in to comment.