Azure DataWarehouse使用外部表加载CSV

时间:2018-09-11 15:27:34

标签: azure-storage-blobs sql-data-warehouse

我找不到完整的示例,说明如何将带有外部表的CSV文件直接加载到Sql Datawarehouse中。 该文件位于存储帐户https://tstodummy.blob.core.windows.net/上 Blob容器referencedata-in,文件夹csv-uploads,文件something.csv。 这是我的代码

CREATE DATABASE SCOPED CREDENTIAL tstodummy_refdata_credential
  WITH IDENTITY = 'USER',
  SECRET = '....'
GO

CREATE EXTERNAL DATA SOURCE tstodummy_referencedata
  WITH ( TYPE = HADOOP,
         LOCATION = 'wasb://referencedata-in@tstodummy.blob.core.windows.net',
         CREDENTIAL = tstodummy_refdata_credential);
GO

CREATE EXTERNAL FILE FORMAT aps_bma_referencedata_ff
WITH (FORMAT_TYPE = DELIMITEDTEXT,
      FORMAT_OPTIONS(
          FIELD_TERMINATOR = ';',
          STRING_DELIMITER = '"',
          FIRST_ROW = 2, 
          USE_TYPE_DEFAULT = True)
)

CREATE EXTERNAL TABLE [stg_aps_bma_refdata].[PlanDeMaintenance]
  ( [Version]     VARCHAR(255) NULL
  , [Description] VARCHAR(255) NULL
  , [Date_Start]  VARCHAR(255) NULL
  , [Date_Stop]   VARCHAR(255) NULL
  ) WITH ( LOCATION = '\referencedata-in\csv-uploads\PlanDeMaintanance'
         , DATA_SOURCE = tstodummy_referencedata
         , FILE_FORMAT = aps_bma_referencedata_ff
         , REJECT_TYPE = VALUE
         , REJECT_VALUE = 0
         )

我在Location中一直在玩各种组合...但是,Nogo 错误是

Msg 105002, Level 16, State 1, Line 26
EXTERNAL TABLE access failed because the specified path name '/referencedata-in/csv-uploads/PlanDeMaintanance.csv' does not exist. Enter a valid path and try again.

1 个答案:

答案 0 :(得分:0)

最后,在其他人遇到销售麻烦的情况下,这样做就成功了。 我尚未在代码中添加我收到的评论,同时完成了。

CREATE EXTERNAL DATA SOURCE tsto_referencedata
  WITH ( TYPE = HADOOP,
         LOCATION = 'wasb://referencedata-in@tsto.blob.core.windows.net',
         CREDENTIAL = tsto_refdata_credential);
GO

CREATE EXTERNAL FILE FORMAT aps_bma_referencedata_ff
WITH (FORMAT_TYPE = DELIMITEDTEXT,
      FORMAT_OPTIONS(
          FIELD_TERMINATOR = ',',
          STRING_DELIMITER = '"',
          FIRST_ROW = 2, 
          USE_TYPE_DEFAULT = True)
)

CREATE EXTERNAL TABLE [stg_aps_bma_refdata].[PlanDeMaintenance.csv]
  ( [Version]     VARCHAR(255) NULL
  , [Description] VARCHAR(255) NULL
  , [Date_Start]  VARCHAR(255) NULL
  , [Date_Stop]   VARCHAR(255) NULL
  ) WITH ( LOCATION = '/csv-uploads/PlanDeMaintenance.csv'
         , DATA_SOURCE = tsto_referencedata
         , FILE_FORMAT = aps_bma_referencedata_ff
         , REJECT_TYPE = VALUE
         , REJECT_VALUE = 0
         )