3

昨天我尝试使用Azure ML中的“应用SQL变换”模块中使用的相同sqlite脚本,在SQLite的Python模块在Azure的ML:“执行Python脚本”模块中的Azure ML:sqlite3不支持公用表表达式

with tbl as (select * from t1) 
select * from tbl 

这是我得到的错误:

[Critical]  Error: Error 0085: The following error occurred during script evaluation, please view the output log for more information: 
---------- Start of error message from Python interpreter ---------- 
    File "C:\server\invokepy.py", line 169, in batch 
data:text/plain,Caught exception while executing function: Traceback (most recent call last): 
    odfs = mod.azureml_main(*idfs) 
    File "C:\pyhome\lib\site-packages\pandas\io\sql.py", line 388, in read_sql 
    File "C:\temp\azuremod.py", line 193, in azureml_main 
    results = pd.read_sql(query,con) 
    coerce_float=coerce_float, parse_dates=parse_dates) 
    File "C:\pyhome\lib\site-packages\pandas\io\sql.py", line 1017, in execute 
    File "C:\pyhome\lib\site-packages\pandas\io\sql.py", line 1022, in read_sql 
    cursor = self.execute(*args) 
    raise_with_traceback(ex) 
    File "C:\pyhome\lib\site-packages\pandas\io\sql.py", line 1006, in execute 
---------- End of error message from Python interpreter ---------- 
    cur.execute(*args) 
DatabaseError: Execution failed on sql: with tbl as (select * from t1) 
        select * from tbl 

和Python代码:

def azureml_main(dataframe1 = None, dataframe2 = None): 
    import pandas as pd 
    import sqlite3 as lite 
    import sys 
    con = lite.connect('data1.db') 
    con.text_factory = str 
    with con: 
     cur = con.cursor() 

     if (dataframe1 is not None): 
      cur.execute("DROP TABLE IF EXISTS t1") 
      dataframe1.to_sql('t1',con) 
     query = '''with tbl as (select * from t1) 
        select * from tbl'''      
     results = pd.read_sql(query,con)  

    return results, 

与替换查询时:

select * from t1 

它的工作如预期。 正如你可能知道的,公用表表达式是Sqlite的一个关键特性,运行递归代码的能力是Sqlite等任何函数式语言中的“必备”。

我也尝试在Azure Jupyter Notebook中运行我的Python脚本,该脚本也按预期工作。

是否有可能我们在Python模块中的Sqlite的配置比在Jupyter Notebook和“Apply SQL Transformation”模块中有不同的配置?

+0

便宜无答案是尝试添加您想要的特定版本的sqllite3,这里是一个指南。 http://blogs.msdn.com/b/andreasderuiter/archive/2015/02/16/azure-ml-now-apparently-supports-executing-python-scripts.aspx但我实际上并没有看到sqllite3列表...很可能笔记本和模块软件包版本不同步。 –

回答

2

我转载了您的问题,并审查了pandas.io.sqlSQL Queries文档http://pandas.pydata.org/pandas-docs/stable/io.html#sql-queries。我试图用read_sql_query来解决它,但失败了。

根据pandas文档,似乎Pandas不支持此SQL语法的用法。

根据我的经验和根据您的SQL,我试图执行SQL select * from (select * from t1) as tbl而不是您的SQL为Pandas工作。

希望它有帮助。最好的祝福。

相关问题