我正在尝试通过 polybase 加载多个文件,并在创建视图时向我抛出错误。
select * from dbo.test
fname lname
a.csv null
b.csv null
我能够成功创建数据源和外部表而没有任何问题。
代码错误
Error in the code.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'DATA_FILE_NAME'.
Invalid column name 'DATA_FILE_NAME'.
Invalid column name 'DATA_FILE_NAME'.
Invalid column name 'DATA_FILE_NAME'.
Invalid column name 'DATA_FILE_NAME'.
Invalid column name 'DATA_FILE_NAME'.
Invalid column name 'DATA_FILE_NAME'.
Invalid column name 'DATA_FILE_NAME'.
Invalid column name 'DATA_FILE_NAME'.
Invalid column name 'DATA_FILE_NAME'.
代码
IF OBJECT_ID('dbo.TEST_V', 'V') IS NOT NULL
DROP VIEW [dbo].[TEST_V]
GO
-- Create new view
CREATE VIEW [dbo].[TEST_V]
AS
-- Add dynamic T-SQL to temporary table
SELECT
-- Auto increment number
ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS ROW_ID,
-- Data file name
DATA_FILE_NAME AS DATA_FILE,
-- Drop external table if it exists
'IF EXISTS (SELECT * FROM sys.external_tables WHERE NAME = ' +
CHAR(39) + SUBSTRING(DATA_FILE_NAME, 1, LEN(DATA_FILE_NAME) - 11) + CHAR(39) + ') ' +
'DROP EXTERNAL TABLE [dbo].[' + SUBSTRING(DATA_FILE_NAME, 1, LEN(DATA_FILE_NAME) - 11) + '];' AS DROP_STMT,
-- Create new external table
'CREATE EXTERNAL TABLE [dbo].[' + SUBSTRING(DATA_FILE_NAME, 1, LEN(DATA_FILE_NAME) - 11) + '] ' +
'( ' +
'fname [varchar] (70), ' +
'lname [varchar] (70) ' +
') ' +
'WITH ' +
'( ' +
'LOCATION=' + CHAR(39) + '/NEW/' + DATA_FILE_NAME + CHAR(39) + ' ' +
', DATA_SOURCE = SIMPLE' +
', FILE_FORMAT = SIMPLE_HEADER' +
', REJECT_TYPE = VALUE ' +
', REJECT_VALUE = 1 ' +
') ' AS CREATE_STMT,
-- Move data into staging table
'INSERT INTO dbo.fname ' +
'SELECT ' +
' fname ,' +
' lname ' +
'FROM [dbo].[' + SUBSTRING(DATA_FILE_NAME, 1, LEN(DATA_FILE_NAME) - 11) + '] ' +
';' AS INSERT_STMT
FROM
[dbo].[test];
GO
我正在尝试使用上述视图创建过程以动态使用多个文件加载数据。