/* parqit use - Open a lazy view or load data into memory *! VERSION 0.1.37 07sep2026 User > parqit > Read data (lazy view or into memory)... Launch directly with: db parqit_read (menu installed by: parqit menu) Builds parqit use (lazy view, or into memory with clear), parqit open _data and parqit path. The Populate button fills the variable picker from the Parquet footer of the source, as Stata's use/describe/merge dialogs do for a dataset on disk; Describe runs parqit describe on the source. */ VERSION 16.0 INCLUDE _std_wide DEFINE _dlght 400 INCLUDE header HELP hlp1, view("help parqit##lazy") RESET res1 SCRIPT PREINIT BEGIN create STRING dlgname dlgname.storeDialogClassName create DOUBLE pq_populate_error main.fi_using.formatfilter /// "Parquet (*.parquet)|*.parquet|" /// "Delimited text (*.csv *.tsv *.txt *.tab)|*.csv;*.tsv;*.txt;*.tab|" /// "Stata data (*.dta)|*.dta|" /// "Excel (*.xlsx *.xls)|*.xlsx;*.xls|" /// "All files (*.*)|*.*" END PROGRAM POSTINIT_PROGRAM BEGIN call program main_mode call program main_context END DIALOG main, label("parqit use - Open a lazy view or load data into memory") /// tabtitle("Main") BEGIN GROUPBOX gb_what _lft _top _iwd _ht6, /// label("Operation") RADIO rb_use _ilft _ss _ibwd ., /// first /// onclickon(program main_mode) /// label("Open a lazy view over a source, or read the source into memory (parqit use)") RADIO rb_open @ _ss @ ., /// onclickon(program main_mode) /// label("Open the data in memory as a lazy view (parqit open _data)") RADIO rb_path @ _ss @ ., /// last /// onclickon(program main_mode) /// label("Resolve a path and report whether it exists (parqit path)") TEXT tx_using _lft 110 _lw80 ., /// label("Filename, glob (data_*.parquet), Hive directory, or other supported source:") BUTTON bu_desc _rj80 @ 80 ., /// onpush(program main_describe) /// tooltip("Describe the Parquet footer of the source (parqit describe)") /// label("Describe") FILE fi_using _lft _ss _iwd ., /// onchange(program main_source) /// error("Filename") /// defext(parquet) /// label("Browse...") TEXT tx_vars _lft _ls _lw80 ., /// label("Variables to read (leave empty for all variables):") BUTTON bu_pop _rj80 @ 80 ., /// onpush(program main_populate) /// tooltip("Populate combobox with the variable names in the Parquet source") /// label("Populate") COMBOBOX cb_vars _lft _ss _iwd ., /// append /// dropdown /// contents(vv_list) /// label("Variables to read") CHECKBOX ck_clear _lft _ls _iwd ., /// option(clear) /// onclickon(program main_mode) /// onclickoff(program main_mode) /// label("Read the data into memory now, replacing the data in memory (clear); otherwise a lazy view is opened") TEXT tx_name _lft _ls _cwd1 ., /// label("View name (optional; the default view is named default):") EDIT ed_name @ _ss _vnwd ., /// max(32) /// option(name) /// label("View name") TEXT tx_enc _lft2 -20 _cwd1 ., /// label("Code page of legacy text (.dta or Excel source):") COMBOBOX cb_enc @ _ss _vnwd ., /// dropdownlist /// contents(enc_list) /// default("windows-1252") /// option(encoding) /// label("Code page") CHECKBOX ck_relaxed _lft _ls _iwd ., /// option(relaxed) /// label("Union files with different schemas by column name (relaxed)") TEXT tx_note _lft _ls _iwd ., /// label("A lazy view probes the schema and loads no result rows; materialise it later with parqit collect or parqit save.") TEXT tx_context _lft 360 470 ., label("Current view: refresh to check") BUTTON bu_context _rj80 @ 80 ., label("Refresh") onpush(program main_context) END LIST vv_list BEGIN END LIST enc_list BEGIN windows-1252 latin1 latin9 macroman END PROGRAM main_mode BEGIN if main.rb_use { call main.tx_using.enable call main.fi_using.enable call main.bu_desc.enable call main.tx_vars.enable call main.bu_pop.enable call main.cb_vars.enable call main.ck_clear.enable call main.ck_relaxed.enable call main.tx_enc.enable call main.cb_enc.enable if main.ck_clear { call main.tx_name.disable call main.ed_name.disable } else { call main.tx_name.enable call main.ed_name.enable } call program main_source } if main.rb_open { call main.tx_using.disable call main.fi_using.disable call main.bu_desc.disable call main.tx_vars.disable call main.bu_pop.disable call main.cb_vars.disable call main.ck_clear.disable call main.ck_relaxed.disable call main.tx_name.enable call main.ed_name.enable call main.tx_enc.enable call main.cb_enc.enable } if main.rb_path { call main.tx_using.enable call main.fi_using.enable call main.bu_desc.enable call main.tx_vars.disable call main.bu_pop.disable call main.cb_vars.disable call main.ck_clear.disable call main.ck_relaxed.disable call main.tx_name.disable call main.ed_name.disable call main.tx_enc.disable call main.cb_enc.disable } END PROGRAM main_context BEGIN put "parqit _dlgcontext " put dlgname stata hidden queue clear END PROGRAM main_source BEGIN if main.rb_use { put "parqit _dlgsource " put dlgname if main.fi_using { put " using " put /smartquote main.fi_using } stata hidden queue clear } END PROGRAM main_describe BEGIN require main.fi_using put "parqit describe " put /smartquote main.fi_using stata END PROGRAM main_populate BEGIN require main.fi_using call pq_populate_error.setvalue 0 put "parqit _dlgvars " put dlgname put " vv_list using " put /smartquote main.fi_using stata hidden immediate if pq_populate_error { stopbox stop "Unable to get the variable names from the source." /// "Populate reads the footer of a Parquet file, glob, or Hive directory." } call main.cb_vars.repopulate END PROGRAM command BEGIN if main.rb_use { require main.fi_using put "parqit use " if main.cb_vars { put main.cb_vars " " } put "using " put /smartquote main.fi_using beginoptions option main.ck_clear if !main.ck_clear { optionarg main.ed_name } option main.ck_relaxed optionarg /hidedefault main.cb_enc endoptions } if main.rb_open { put "parqit open _data" beginoptions optionarg main.ed_name optionarg /hidedefault main.cb_enc endoptions } if main.rb_path { require main.fi_using put "parqit path " put /smartquote main.fi_using } END