c# - 如何将带有代码的 csv 文件导入表格模型
问题描述
我正在设置一个网络服务,用户上传 csv 文件,然后将其添加到 SASS 表格模型中。这甚至可以通过代码实现吗?如果是这样怎么做?我知道你可以通过 VS 手动完成,但我需要它自动完成。
可以解决将 csv 文件上传到 sql 数据库并从那里以表格模式加载的解决方法。但由于文件大小非常大(~500Mb),它可能会在一段时间内执行此操作。
我当前的代码,连接到 SASS 服务器并将数据从 sql 数据库复制到 SASS
public void Add()
{
string connStr = @"Data Source=localhost:64731";
string dataSource = "AdventureWorksDW2017";
string measureExpression = @"SUM('DimEployee'[Freq])";
using (Server serv = new Server())
{
serv.Connect(connStr);
string dbName = serv.Databases.GetNewName("TestBase3000");
Database db = new Database()
{
Name = dbName,
ID = dbName,
CompatibilityLevel = 1200,
StorageEngineUsed = StorageEngineUsed.TabularMetadata
};
db.Model = new Model()
{
Name = "Tabular model test",
Description = "Test"
};
//define data source
db.Model.DataSources.Add(new ProviderDataSource()
{
Name = dataSource,
Description = "Aventure works",
//for SQL server
ConnectionString =
@"Provider=SQLNCLI11;Data Source=DESKTOP-K9RTS02\SQLEXPRESS;Initial Catalog=AdventureWorksDW2017;Integrated Security=SSPI",
ImpersonationMode = Microsoft.AnalysisServices.Tabular.ImpersonationMode.ImpersonateServiceAccount,
});
// add tables
// dimension table
db.Model.Tables.Add(new Table()
{
Name = db.Model.Tables.GetNewName("DimProductSubcategory"),
Description = "Testing",
Partitions =
{
new Partition()
{
Name = "Partition 1",
Source = new QueryPartitionSource()
{
DataSource = db.Model.DataSources[dataSource],
Query = @"SELECT ProductSubcategoryKey, ProductSubcategoryAlternateKey, EnglishProductSubcategoryName FROM DimProductSubcategory",
}
}
},
Columns =
{
new Microsoft.AnalysisServices.Tabular.DataColumn()
{
Name = "Id",
DataType = DataType.Int64,
SourceColumn = "ProductSubcategoryKey",
},
new Microsoft.AnalysisServices.Tabular.DataColumn()
{
Name = "AltId",
DataType = DataType.Int64,
SourceColumn = "ProductSubcategoryAlternateKey",
},
new Microsoft.AnalysisServices.Tabular.DataColumn()
{
Name = "EnglishSubCategory",
DataType = DataType.String,
SourceColumn = "EnglishProductSubcategoryName",
}
}
});
serv.Databases.Add(db);
//deploy database to SSAS Server
db.Update(UpdateOptions.ExpandFull);
//process new model so it's available to query
db.Model.RequestRefresh(Microsoft.AnalysisServices.Tabular.RefreshType.Full);
db.Update(UpdateOptions.ExpandFull);
}
解决方案
推荐阅读
- html - 下拉悬停菜单未显示在 IE/Edge 中
- image - 从 ResourceStream 加载 PNG 图像的函数不返回任何内容
- if-statement - 使用 if 状态级联多个条件,以创建 2 个分类列
- javascript - C# ChromiumWebBrowser 获取图像(验证码)
- graphql - 如何从 Apollo Server 进行 GraphQL 查询和突变?
- soap - QuickBooks Web 连接器 - 找不到 SOAP 响应
- payara-micro - Payara Micro:如何使用 slf4j(或 log4j2)登录?
- r - ggplot 不重新排序变量;警告信息需要估计手段
- html - 引导行搞砸了
- azure - 使用 terraform 配置程序“local-exec”运行 shell 脚本在 Azure DevOps 中返回权限被拒绝返回权限被拒绝