简体   繁体   English

如何在 Foundry Code Authoring 的 python 转换环境中使用 sqlContext(执行 SQL 查询)?

[英]How can I use sqlContext (to execute SQL queries) in the python transform environment in Foundry Code Authoring?

I have done the following in an authoring我在创作中做了以下事情

    Output(test_dataset_path),
    df=Input(og_dataset_path)
)
def compute(ctx, df):
    ctx.spark_session.sql(f'''
    CREATE TABLE `test_dataset_path` AS
    SELECT * FROM `og_dataset_path`
    ''')

    return ctx.spark_session.sql(f'''
    SELECT * FROM `og_dataset_path`
    ''')

and it is erroring out on the code:它在代码上出错了:

    ctx.spark_session.sql(f'''
    CREATE TABLE `test_dataset_path` AS
    SELECT * FROM `og_dataset_path`
    ''')

with the error: pyspar.sql.utils.AnanlysisException: Table or view not found: og_dataset_path出现错误: pyspar.sql.utils.AnanlysisException: Table or view not found: og_dataset_path

How can I resolve this error?如何解决此错误?

Using createOrReplaceTempView should resolve this problem:使用 createOrReplaceTempView 应该可以解决这个问题:

from transforms.api import transform_df, Input, Output

@transform_df(
     Output("/Users/XXXXX/sqlcsvA2"),
     ALL=Input("/datasources/locations/data/cleaned")
)
def my_compute_function(ctx, ALL):
    ALL.createOrReplaceTempView('ALL')
    return ctx.spark_session.sql('select * from ALL limit 10')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Foundry 代码存储库中,如何从 Python 转换中记录调试消息? - In a Foundry Code Repository, how do I log debug messages from within a Python transform? 在 Palantir Foundry 中,我怎样才能只在我的 Python Transform 的某些分支上运行测试? - In Palantir Foundry, how can I only run tests on some branches of my Python Transform? PALANTIR-FOUNDRY:如何在转换中添加 dataframe 的描述? - PALANTIR-FOUNDRY: How can I add a description for a dataframe in a transform? 如何在 Foundry 代码库中运行 pytesseract / tesseract? - How can I run pytesseract / tesseract in Foundry Code Repositories? 是否可以从代工厂代码创作中找到数据集的最后一个代工厂同步日期? - Is it possible to find the last foundry sync date of a dataset from foundry code authoring? 如何从代码存储库中找到 Foundry API? - How can I hit a Foundry API from Code Repositories? 如何从 Blobster API 获取文件到 Foundry 转换? - How do I get a file from the Blobster API into a Foundry Transform? 如何在 Foundry 代码存储库中使用本地 IDE 进行 Java 转换? - How do I use a local IDE for Java Transforms in Foundry Code Repositories? 如何在 Foundry Code Workbook 中生成身份验证令牌以用作 API 的参数? - How do I generate authentication tokens within Foundry Code Workbook to use as an argument to APIs? 我可以在 Foundry 代码工作簿中保存 .png 吗? - Can I save a .png in a Foundry Code Workbook?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM