小编Rag*_*ath的帖子

alter table然后在单个语句中更新

我有一个要求,我需要更改(添加2列),然后更新同一个表.

这是我试过的查询:

ALTER TABLE A
ADD c1 int,c2 varchar(10)

UPDATE  A set c1 = 23, c2 = 'ZZXX'
Run Code Online (Sandbox Code Playgroud)

我需要一次运行上面两个查询.

我正在使用Talend ETL工具,在这里我们有一个组件tMssqlrow,它允许我们运行多个查询(我在单个组件中使用10到15个更新查询).

但上面的查询不起作用.

我在DataBase Microsoft SQL中测试过.我收到以下错误:

Msg 207,Level 16,State 1,Line 5

列名称"c1"无效.消息207,

16级,1号,5号线

列名称"c2"无效.

任何人都可以帮我解决这个问题.

sql database sql-server etl talend

17
推荐指数
1
解决办法
2万
查看次数

将 Pandas 数据框保存到 Google Cloud 存储桶

我想将 Pandas 数据框直接保存到 Google Cloud Storage。我使用write-a-pandas-dataframe-to-google-cloud-storage-or-bigquery尝试了不同的方法。但我无法保存。

注意:我只能使用 google.cloud 包

下面是我试过的代码

from google.cloud import storage
import pandas as pd
input_dict = [{'Name': 'A', 'Id': 100}, {'Name': 'B', 'Id': 110}, {'Name': 'C', 'Id': 120}]
df = pd.DataFrame(input_dict)
Run Code Online (Sandbox Code Playgroud)

尝试:1

destination = f'gs://bucket_name/test.csv'
df.to_csv(destination)
Run Code Online (Sandbox Code Playgroud)

尝试:2

storage_client = storage.Client(project='project')
bucket = storage_client.get_bucket('bucket_name')
gs_file = bucket.blob('test.csv')
df.to_csv(gs_file)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

对于选项 1:没有这样的文件或目录:'gs://bucket_name/test.csv'

选项 2:'Blob' 对象没有属性 'close'

谢谢,

拉古纳特。

python pandas google-cloud-storage google-cloud-platform

5
推荐指数
2
解决办法
9422
查看次数

将 BigQuery 表导出到 Google Storage 时如何避免标头

我开发了以下代码,有助于将 BigQuery 表导出到 Google 存储桶。我想将文件合并到没有标头的单个文件中,以便下一个进程将使用文件而不会出现任何问题。

    def export_bq_table_to_gcs(self, table_name):
        client = bigquery.Client(project=project_name)

        print("Exporting table {}".format(table_name))
        dataset_ref = client.dataset(dataset_name,
                                     project=project_name)
        dataset = bigquery.Dataset(dataset_ref)
        table_ref = dataset.table(table_name)
        size_bytes = client.get_table(table_ref).num_bytes

        # For tables bigger than 1GB uses Google auto split, otherwise export is forced in a single file.
        if size_bytes > 10 ** 9:
            destination_uris = [
                      'gs://{}/{}{}*.csv'.format(bucket_name,
                                       f'{table_name}_temp', uid)]
        else:
            destination_uris = [
                      'gs://{}/{}{}.csv'.format(bucket_name,
                                      f'{table_name}_temp', uid)]

        extract_job = client.extract_table(table_ref, destination_uris)  # API request
        result = extract_job.result()  # Waits for job to complete. …
Run Code Online (Sandbox Code Playgroud)

python-3.x google-cloud-storage google-bigquery

3
推荐指数
1
解决办法
2595
查看次数

无法在 BigQuery 中使用 DML 语句在作业中设置目标表

我正在编写 Python 代码以使用 bigquery.Client.query 执行 BigQuery sql 命令。我在 DML 语句异常的作业中无法设置目标表

下面是我正在使用的 Python 代码

if query_file_name:
    with open(query_file_name, mode="r") as query_file:
        query = query_file.read()

job_config = bigquery.QueryJobConfig()
job_config.use_legacy_sql = use_legacy_sql

if destination:
    if destination.partitioned_field:
        job_config.time_partitioning = TimePartitioning(type_=TimePartitioningType.DAY, 
                                         field=destination.partitioned_field)
google_bq_table = self.fetch_table_reference(destination)
job_config.destination = google_bq_table

job_config.write_disposition = WriteDisposition.WRITE_APPEND

query_job = self.google_client.query(query, job_config=job_config)  # API request - starts the query asynchronously
Run Code Online (Sandbox Code Playgroud)

我有 query_file 如下 BigQuery sql

INSERT mydataset.target_table
        (col1, col2, col3, created_date)
WITH T AS (SELECT col1, col2, col3, …
Run Code Online (Sandbox Code Playgroud)

python-3.x google-bigquery

2
推荐指数
1
解决办法
8712
查看次数