Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue found on page 'Internal Errors' #436

Open
Midland-tanaka opened this issue Oct 23, 2024 · 0 comments
Open

Issue found on page 'Internal Errors' #436

Midland-tanaka opened this issue Oct 23, 2024 · 0 comments

Comments

@Midland-tanaka
Copy link

Midland-tanaka commented Oct 23, 2024

Please describe the problem you encountered in the DuckDB documentation and include the "Page URL" link shown below.

import duckdb
import os
import pandas as pd

import pyexcel as p
import os

def convert_xls_to_xlsx(file_path):
    # Đọc file .xls
    sheet = p.get_sheet(file_name=file_path)
    
    # Tạo file .xlsx mới
    new_file_path = file_path.replace('.xls', '.xlsx')
    
    # Lưu dữ liệu vào file .xlsx
    sheet.save_as(new_file_path)
    print(f"Đã chuyển đổi {file_path} thành {new_file_path}")
    
    # Xóa file .xls sau khi chuyển đổi
    if os.path.exists(new_file_path):
        os.remove(file_path)  # Xóa file .xls
        print(f"Đã xóa file cũ: {file_path}")
    
    return new_file_path

# Đường dẫn thư mục chứa file .xls và .xlsx của bạn
path_table3 = r'D:\data\CAR\AR_CONTRACT'
#r'D:\workspace\Zeppelin\data_debt_group\data_it\TABLE_LOAN_UPDATE'

# Lặp qua các file trong thư mục và chuyển đổi file .xls thành .xlsx
for file_name in os.listdir(path_table3):
    if file_name.endswith('.xls'):
        file_path = os.path.join(path_table3, file_name)
        convert_xls_to_xlsx(file_path)

def combine_excel_files_duckdb(directory_path):
    # Kết nối DuckDB
    con = duckdb.connect()

    # Cài đặt và nạp tiện ích mở rộng spatial
    con.execute("INSTALL spatial;")
    con.execute("LOAD spatial;")

    data_frames = []

    # Lặp qua từng file trong thư mục
    for file_name in os.listdir(directory_path):
        if file_name.endswith('.xlsx') or file_name.endswith('.xls'):
            file_path = os.path.join(directory_path, file_name)
            
            # Đọc file Excel bằng DuckDB với st_read
            query = f"SELECT DATA_DATE FROM st_read('{file_path}')"
            df = con.execute(query).fetchdf()
            
            data_frames.append(df)
            print(f"Đã đọc file: {file_name}")
    
    # Kết hợp tất cả các DataFrame
    combined_df = pd.concat(data_frames, ignore_index=True)

    return combined_df

Gọi hàm

stm_table3 = combine_excel_files_duckdb(path_table3)
InternalException: INTERNAL Error: Failed to bind "ST_Read": Table function must return at least one column
This error signals an assertion failure within DuckDB. This usually occurs due to unexpected conditions or errors in the program's logic.
For more information, see https://duckdb.org/docs/dev/internal_errors
@szarnyasg szarnyasg transferred this issue from duckdb/duckdb-web Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant