Garrett Weaver
05/30/2025, 11:10 PMGarrett Weaver
05/30/2025, 11:12 PMunion_all_by_name, in which the case the column with type null was duplicated because the matching column in the other dataset had the proper type since it had non-null valuesColin Ho
06/02/2025, 4:50 PMColin Ho
06/02/2025, 4:52 PMjoin or from the union_all_by_name?Garrett Weaver
06/02/2025, 9:31 PMimport sqlite3
import daft
import sqlalchemy
conn = sqlite3.connect("school.db")
cursor = conn.cursor()
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS students (
student_id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER
)
"""
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS courses (
course_id INTEGER PRIMARY KEY,
course_name TEXT,
student_id INTEGER,
FOREIGN KEY (student_id) REFERENCES students (student_id)
)
"""
)
cursor.execute("INSERT INTO students (name, age) VALUES (?, ?)", ("John Doe", None))
cursor.execute("INSERT INTO students (name, age) VALUES (?, ?)", ("Jane Smith", None))
cursor.execute(
"INSERT INTO courses (course_name, student_id) VALUES (?, ?)", ("Mathematics", 1)
)
cursor.execute(
"INSERT INTO courses (course_name, student_id) VALUES (?, ?)", ("Science", 1)
)
cursor.execute(
"INSERT INTO courses (course_name, student_id) VALUES (?, ?)", ("Literature", 2)
)
conn.commit()
conn.close()
def create_conn():
return sqlalchemy.create_engine("sqlite:///school.db").connect()
daft.read_sql(
"SELECT * FROM courses LEFT JOIN students ON courses.student_id = students.student_id",
create_conn,
).show()Garrett Weaver
06/02/2025, 9:32 PMGarrett Weaver
06/02/2025, 9:32 PMjust want to check, does the column with null type come from thefrom the join as in the toy exampleor from thejoin?union_all_by_name
Colin Ho
06/02/2025, 9:36 PM"SELECT * FROM students" in this example, and the age column is also NULLColin Ho
06/02/2025, 9:37 PMdaft.read_sql(
"SELECT * FROM courses LEFT JOIN students ON courses.student_id = students.student_id",
create_conn,
schema={
"age": daft.DataType.int64(),
},
).show()Garrett Weaver
06/02/2025, 9:38 PMGarrett Weaver
06/02/2025, 9:38 PMColin Ho
06/02/2025, 9:42 PMinfer_schema and schema, by default infer_schema is true and schema will act as a hinting mechanism, so you don't need to list out all the expected types, only the problematic ones. But if you set infer_schema=False, then schema must be passed in and will act as the definitive schema, bypassing schema inference