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

minor: SessionStateBuilder::with_default_features ergonomics #14899

Open
milenkovicm opened this issue Feb 26, 2025 · 3 comments · May be fixed by #14935
Open

minor: SessionStateBuilder::with_default_features ergonomics #14899

milenkovicm opened this issue Feb 26, 2025 · 3 comments · May be fixed by #14935
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@milenkovicm
Copy link
Contributor

milenkovicm commented Feb 26, 2025

Is your feature request related to a problem or challenge?

Just a small note about ergonomics of SessionStateBuilder, as I spent some time to figure out why:

    let session_state = SessionStateBuilder::new()
        .with_table_factory("DELTA_TABLE".to_string(), Arc::new(DeltaTableFactory {}))
        .with_default_features()
        .build();
    let ctx = SessionContext::new_with_state(session_state);

    ctx.sql("create external table dt stored as delta_table location './data/append_table/'")
        .await
        .unwrap()
        .show()
        .await
        .unwrap();

fails with Execution("Unable to find factory for DELTA_TABLE")?

Apparently ordering of with_ methods matters as

    let session_state = SessionStateBuilder::new()
        .with_default_features()
        .with_table_factory("DELTA_TABLE".to_string(), Arc::new(DeltaTableFactory {}))
        .build();

will work as expected.

Apparently, with_default_features will override table factories if called last (like I would usually do):

pub fn with_default_features(self) -> Self {
        self.with_table_factories(SessionStateDefaults::default_table_factories())
            .with_file_formats(SessionStateDefaults::default_file_formats())
            .with_expr_planners(SessionStateDefaults::default_expr_planners())
            .with_scalar_functions(SessionStateDefaults::default_scalar_functions())
            .with_aggregate_functions(SessionStateDefaults::default_aggregate_functions())
            .with_window_functions(SessionStateDefaults::default_window_functions())
            .with_table_function_list(SessionStateDefaults::default_table_functions())
    }

Describe the solution you'd like

Would it make sense from ergonomic perspective to make with_default_features() rather than with_default_features(self) and force it to be the first statement in the builder.

Describe alternatives you've considered

It can stay as it is, I might be pedantic, but would make sense to document it (which I personally would probably miss)
or don't override/join values if already there.

Additional context

No response

@milenkovicm milenkovicm added the enhancement New feature or request label Feb 26, 2025
@alamb
Copy link
Contributor

alamb commented Feb 26, 2025

I agree it would be great not to override any existing table providers 👍

@alamb alamb added the good first issue Good for newcomers label Feb 26, 2025
@alamb
Copy link
Contributor

alamb commented Feb 26, 2025

Seems like a good first issue to me

@irenjj
Copy link
Contributor

irenjj commented Feb 28, 2025

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
3 participants