Best Python code snippet using dbt-osmosis_python
app.py
Source:app.py  
...182        pandas_profiling.report.presentation.core.html.HTML: lambda _: state[COMPILED_SQL],183    },184    allow_output_mutation=True,185)186def convert_profile_report_to_html(profile: pandas_profiling.ProfileReport) -> str:187    return profile.to_html()188st.title("dbt-osmosis ð")189st.sidebar.header("Profiles")190st.sidebar.write(191    "Select a profile used for materializing, compiling, and testing models. Can be updated at any time."192)193state[TARGET_PROFILE] = st.sidebar.radio(194    f"Loaded profiles from {ctx.config.profile_name}",195    [target for target in state[RAW_PROFILES][ctx.config.profile_name].get("outputs", [])],196    key=PROFILE_SELECTOR,197)198st.sidebar.markdown(f"Current Target: **{state[TARGET_PROFILE]}**")199st.sidebar.write("")200st.sidebar.write("Utility")201# st.sidebar.button("Reload dbt project", key=DBT_DO_RELOAD)202st.sidebar.caption(203    "Refresh the page to reparse dbt. This is useful if any updated models or macros in your physical project \204    on disk have changed and are not yet reflected in the workbench as refable or updated."205)206st.sidebar.write("")207st.sidebar.selectbox("Editor Theme", THEMES, index=8, key=THEME_PICKER)208st.sidebar.selectbox("Editor Language", DIALECTS, key=DIALECT_PICKER)209# IDE LAYOUT210notificationContainer = st.empty()211descriptionContainer = st.container()212compileOptionContainer = st.container()213ideContainer = st.container()214descriptionContainer.markdown(215    """216Welcome to the [dbt-osmosis](https://github.com/z3z1ma/dbt-osmosis) workbench ð. 217The workbench serves as a no fuss way to spin up 218an environment where you can very quickly iterate on dbt models. In an ideal flow, a developer219can spin up the workbench and use it as a _complement_ to their IDE, not a replacement. This means220copying and pasting over a model you are really digging into ð§âð» OR it is just as valid to use 221the workbench as a scratchpad ð·ââï¸. In a full day of development, you may never spin down the workbench.222Refreshing the page is enough to reparse the physical dbt project on disk. The instantaneous feedback223rarely experienced with jinja + ability to execute the SQL both synergize to supercharge â¡ï¸ productivity!224"""225)226if not state[PIVOT_LAYOUT]:227    idePart1, idePart2 = ideContainer.columns(2)228else:229    idePart1 = ideContainer.container()230    idePart2 = ideContainer.container()231compileOptionContainer.write("")232compileOpt1, compileOpt2 = compileOptionContainer.columns(2)233auto_update = compileOpt1.checkbox("Dynamic Compilation", key=DYNAMIC_COMPILATION, value=True)234if auto_update:235    compileOpt1.caption("ð Compiling SQL on change")236else:237    compileOpt1.caption("ð Compiling SQL with control + enter")238compileOpt2.button("Pivot Layout", on_click=toggle_viewer)239with idePart1:240    state[RAW_SQL] = st_ace(241        value=state[RAW_SQL],242        theme=state[THEME_PICKER],243        language=state[DIALECT_PICKER],244        auto_update=auto_update,245        key=f"AceEditor",246        max_lines=35,247        min_lines=20,248        height=500,249    )250with idePart2:251    with st.expander("ð Compiled SQL", expanded=True):252        st.code(253            state[COMPILED_SQL]254            if state[COMPILED_SQL]255            else " --> Invalid Jinja, awaiting model to become valid",256            language="sql",257        )258if compile_sql(state[RAW_SQL]) != state[COMPILED_SQL]:259    state[COMPILED_SQL] = compile_sql(state[RAW_SQL])260    st.experimental_rerun()  # This eager re-run speeds up the app261if ctx.config.target_name != state[TARGET_PROFILE]:  # or state[DBT_DO_RELOAD]:262    print("Reloading dbt project...")263    with notificationContainer:264        ctx.config.target_name = state[TARGET_PROFILE]265        ctx.config.target_name = state[TARGET_PROFILE]266        with st.spinner("Reloading dbt... âï¸"):267            inject_dbt(state[TARGET_PROFILE])268            # state[RAW_SQL] += " "269            state[COMPILED_SQL] = compile_sql(state[RAW_SQL])270    st.experimental_rerun()271# TEST LAYOUT272testHeaderContainer = st.container()273test_column_1, _, test_column_2 = st.columns([1, 2, 1])274testContainer = st.container()275testContainerViewer = testContainer.expander("Result Viewer ð", expanded=True)276test_view_1, _, test_view_2 = testContainerViewer.columns([1, 2, 1])277downloadBtnContainer, profileBtnContainer, profileOptContainer = st.columns([1, 1, 3])278profilerContainer = st.container()279with testHeaderContainer:280    st.write("")281    st.subheader("Osmosis Query Result Inspector ð¬")282    st.write("")283    st.markdown(284        """Run queries against your datawarehouse leveraging the selected target profile. This is a critical step in285    developer productivity ð and dbt-osmosis workbench aims to keep it a click away. Additionally, you can leverage the 286    profiling functionality to get an idea of the dataset you have in memory."""287    ),288    st.write(""), st.write("")289query_limit = test_column_2.number_input(290    "Limit Results", min_value=1, max_value=50_000, value=2_000, step=1, key=QUERY_LIMITER291)292test_column_2.caption(293    "Limit the number of results returned by the query, the maximum value is 50,000"294)295if state[COMPILED_SQL]:296    test_column_1.button(297        "Test Compiled Query",298        on_click=run_query,299        kwargs={"sql": state[COMPILED_SQL], "limit": query_limit},300    )301    test_column_1.caption("This will run the compiled SQL against your data warehouse")302with testContainerViewer:303    st.write("\n\n\n\n\n")304    if state[SQL_QUERY_STATE] == "success":305        test_view_1.write("#### Compiled SQL query results")306    elif state[SQL_QUERY_STATE] == "error":307        test_view_1.warning(f"SQL query error: {state[SQL_ADAPTER_RESP]}")308    if not state[SQL_RESULT].empty:309        test_view_2.info(f"Adapter Response: {state[SQL_ADAPTER_RESP]}")310        st.dataframe(state[SQL_RESULT])311    else:312        st.write("")313        st.markdown(314            "> The results of your workbench query will show up here. Click `Test Compiled Query` to see the results. "315        )316        st.write("")317    st.write("")318with downloadBtnContainer:319    st.download_button(320        label="Download data as CSV",321        data=convert_df_to_csv(state[SQL_RESULT]),322        file_name=f"dbt_osmosis_workbench.csv",323        mime="text/csv",324    )325with profileBtnContainer:326    st.button("Profile Data", key=RUN_PROFILER)327with profileOptContainer:328    st.checkbox("Basic Profiler", key=BASIC_PROFILE_OPT, value=True)329    st.caption(330        "Useful for larger datasets, use the minimal pandas-profiling option for a simpler report"331    )332if state[RUN_PROFILER]:333    pr = build_profile_report(state[SQL_RESULT], state[BASIC_PROFILE_OPT])334    with profilerContainer:335        st_profile_report(pr, height=650)336        st.download_button(337            label="Download profile report",338            data=convert_profile_report_to_html(pr),339            file_name=f"dbt_osmosis_workbench_profile.html",340            mime="text/html",341            key=PROFILE_DOWNLOADER,342        )343        st.write("")344st.write(""), st.write("")345footer1, footer2 = st.columns([1, 2])346footer1.header("Useful Links ð§")347footer2.header("RSS Feeds ð¨")348footer1.write("")349footer1.markdown(350    """351##### dbt docs352- [docs.getdbt.com](https://docs.getdbt.com/)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
