/* parqit view - Manage views, run DuckDB SQL, and set engine options *! VERSION 0.1.37 07sep2026 User > parqit > Views, SQL, and engine settings... Launch directly with: db parqit_views (menu installed by: parqit menu) The report buttons run at once with the dialog open (views, show, explain, describe, ds, version, selftest), echoed to the Results window like a typed command. The list box chooses the action that OK or Submit runs: switch, close, or close every view; run a parqit command on another view; open a view from a DuckDB SQL query or add a raw SQL fragment to the current pipeline; or change an engine setting (statamissing, threads, memory_limit, tempdir). */ VERSION 16.0 INCLUDE _std_wide DEFINE _dlght 370 INCLUDE header HELP hlp1, view("help parqit##options") RESET res1 SCRIPT PREINIT BEGIN create STRING dlgname dlgname.storeDialogClassName END PROGRAM POSTINIT_PROGRAM BEGIN call main.lb_op.forceselchange call program main_context END DIALOG main, label("parqit view - Manage views, run DuckDB SQL, and set engine options") /// tabtitle("Main") BEGIN GROUPBOX gb_report _lft _top _iwd _ht2h, /// label("Report on the current view now (the dialog stays open)") BUTTON bu_views _ilft _ss 70 ., /// onpush(program rep_views) /// tooltip("List the open views (parqit views)") /// label("Views") BUTTON bu_show 95 @ 80 ., /// onpush(program rep_show) /// tooltip("Print the SQL the pipeline compiles to (parqit show)") /// label("Show SQL") BUTTON bu_explain 180 @ 70 ., /// onpush(program rep_explain) /// tooltip("Print the engine's query plan (parqit explain)") /// label("Explain") BUTTON bu_desc 255 @ 80 ., /// onpush(program rep_describe) /// tooltip("Describe the view's schema and pipeline depth (parqit describe)") /// label("Describe") BUTTON bu_ds 340 @ 80 ., /// onpush(program rep_ds) /// tooltip("List the variable names (parqit ds)") /// label("Variables") BUTTON bu_version 425 @ 70 ., /// onpush(program rep_version) /// tooltip("Report the parqit, DuckDB, and plugin-interface versions (parqit version)") /// label("Version") BUTTON bu_selftest 500 @ 80 ., /// onpush(program rep_selftest) /// tooltip("End-to-end engine and codec check (parqit selftest)") /// label("Self-test") TEXT tx_op _lft 75 290 ., /// label("Action:") LISTBOX lb_op _lft _ss 290 200, /// contents(op_words) /// values(op_vals) /// onselchangelist(op_change) /// label("Action") TEXT tx_name 315 75 275 ., /// label("View name:") EDIT ed_name 315 _ss _vnwd ., /// max(32) /// label("View name") TEXT tx_cmd 315 _ls 275 ., /// label("Command to run on it (e.g., count):") EDIT ed_cmd 315 _ss 275 ., /// label("Command") TEXT tx_sql 315 _ls 275 ., /// label("DuckDB SQL:") EDIT ed_sql 315 _ss 275 ., /// label("DuckDB SQL") CHECKBOX ck_sqlclear 315 _ls 275 ., /// option(clear) /// onclickon(main.ed_name.disable) /// onclickoff(main.ed_name.enable) /// label("Load the result into memory (clear)") TEXT tx_value 315 _ls 275 ., /// label("Value:") COMBOBOX cb_sm 315 _ss _vnwd ., /// dropdownlist /// contents(sm_list) /// default("on") /// label("statamissing") EDIT ed_value 315 @ 275 ., /// label("Value") TEXT tx_context _lft 325 470 ., label("Current view: refresh to check") BUTTON bu_context _rj80 @ 80 ., label("Refresh") onpush(program main_context) END PROGRAM main_context BEGIN put "parqit _dlgcontext " put dlgname stata hidden queue clear END LIST sm_list BEGIN on off END LIST op_words BEGIN Switch to a view (view) Close a view (close) Close every view (close _all) Run a command on another view (view name:) Open a view from a DuckDB SQL query (sql) Add a SQL fragment to the pipeline (query) Set missing-value mode (set statamissing) Set engine threads (set threads) Set memory limit (set memory_limit) Set spill directory (set tempdir) END LIST op_vals BEGIN switch close closeall run sql query statamissing threads memory_limit tempdir END LIST op_change BEGIN script op_switch script op_close script op_closeall script op_run script op_sql script op_query script op_statamissing script op_threads script op_memory script op_tempdir END SCRIPT all_off BEGIN main.tx_name.disable main.ed_name.disable main.tx_cmd.disable main.ed_cmd.disable main.tx_sql.disable main.ed_sql.disable main.ck_sqlclear.disable main.tx_value.disable main.cb_sm.hide main.ed_value.hide main.tx_name.setlabel "View name:" main.tx_sql.setlabel "DuckDB SQL:" main.tx_value.setlabel "Value:" END SCRIPT op_switch BEGIN script all_off main.tx_name.enable main.ed_name.enable END SCRIPT op_close BEGIN script all_off main.tx_name.enable main.ed_name.enable main.tx_name.setlabel "View name (empty = current view):" END SCRIPT op_closeall BEGIN script all_off END SCRIPT op_run BEGIN script all_off main.tx_name.enable main.ed_name.enable main.tx_cmd.enable main.ed_cmd.enable END SCRIPT op_sql BEGIN script all_off main.tx_name.enable main.tx_name.setlabel "Name of the view to open (optional):" main.tx_sql.enable main.ed_sql.enable main.ck_sqlclear.enable program sql_name_state END PROGRAM sql_name_state BEGIN if main.ck_sqlclear { call main.ed_name.disable } else { call main.ed_name.enable } END SCRIPT op_query BEGIN script all_off main.tx_sql.enable main.ed_sql.enable main.tx_sql.setlabel "SQL fragment appended to the pipeline:" END SCRIPT op_statamissing BEGIN script all_off main.tx_value.enable main.tx_value.setlabel "Mode: on = Stata ordering, off = SQL:" main.cb_sm.show END SCRIPT op_threads BEGIN script all_off main.tx_value.enable main.tx_value.setlabel "Number of engine threads:" main.ed_value.show END SCRIPT op_memory BEGIN script all_off main.tx_value.enable main.tx_value.setlabel "Memory limit (DuckDB size, e.g., 8GB):" main.ed_value.show END SCRIPT op_tempdir BEGIN script all_off main.tx_value.enable main.tx_value.setlabel "Spill directory (existing path):" main.ed_value.show END PROGRAM rep_views BEGIN put "parqit views" stata END PROGRAM rep_show BEGIN put "parqit show" stata END PROGRAM rep_explain BEGIN put "parqit explain" stata END PROGRAM rep_describe BEGIN put "parqit describe" stata END PROGRAM rep_ds BEGIN put "parqit ds" stata END PROGRAM rep_version BEGIN put "parqit version" stata END PROGRAM rep_selftest BEGIN put "parqit selftest" stata END PROGRAM command BEGIN if main.lb_op.equals("switch") { require main.ed_name put "parqit view " main.ed_name } if main.lb_op.equals("close") { put "parqit close" if main.ed_name { put " " main.ed_name } } if main.lb_op.equals("closeall") { put "parqit close _all" } if main.lb_op.equals("run") { require main.ed_name require main.ed_cmd put "parqit view " main.ed_name ": " main.ed_cmd } if main.lb_op.equals("sql") { require main.ed_sql put "parqit sql " put /smartquote main.ed_sql beginoptions option main.ck_sqlclear if !main.ck_sqlclear { if main.ed_name { put "name(" main.ed_name ")" } } endoptions } if main.lb_op.equals("query") { require main.ed_sql put "parqit query " put /smartquote main.ed_sql } if main.lb_op.equals("statamissing") { put "parqit set statamissing " main.cb_sm } if main.lb_op.equals("threads") { require main.ed_value put "parqit set threads " main.ed_value } if main.lb_op.equals("memory_limit") { require main.ed_value put "parqit set memory_limit " main.ed_value } if main.lb_op.equals("tempdir") { require main.ed_value put "parqit set tempdir " put /smartquote main.ed_value } END