parquet_settings_from_env Subroutine

public subroutine parquet_settings_from_env()

Applies every PARQUET_FORTRAN_* environment variable that is set, through the knob's own setter.

Called by you, never automatically. Reading the environment lazily on first access would be a data race the first time two threads touched a setting, so there is no hidden call: put this near the top of your program, before other threads exist and before any reader, writer or table is opened -- the same contract every setting in this module has.

One variable per knob, named PARQUET_FORTRAN_ plus the knob's own name upper-cased, exactly as parquet_print_settings prints it (PARQUET_FORTRAN_SORT_THREADS, PARQUET_FORTRAN_VERBOSITY, ...). The one name worth knowing in advance is PARQUET_FORTRAN_ARROW_THREADS, whose setter is called parquet_set_arrow_threads -- the variable follows the printed name, not the setter. See doc/pages/operating/settings.md for the full table.

It applies over what is already set; it does not reset. A variable that is absent leaves its knob exactly as it was, so calling this after your own parquet_set_* calls lets the environment override them, and calling it before lets your code win.

A variable that is set but EMPTY is treated as unset, not as an error -- so PARQUET_FORTRAN_VERBOSITY= does nothing at all. Worth knowing when a variable seems to be ignored: export PARQUET_FORTRAN_VERBOSITY=$LEVEL with LEVEL itself unset produces an empty value and is silently skipped. parquet_print_settings is what answers "did my environment actually apply".

Any other bad value aborts, naming the variable, the value and what was expected, rather than being ignored -- a mistyped setting that silently does nothing is the failure this whole module is built to avoid.

Arguments

None

Source Code

    subroutine parquet_settings_from_env()
        character(len=:), allocatable :: text
        logical :: got, flag
        integer :: n32
        integer(int64) :: n64

        ! PARQUET_FORTRAN_THREADS first, deliberately: it sets all three thread counts, so the three
        ! specific variables below must be able to override it. This is the ONE place in this
        ! sequence where the order is load-bearing -- everywhere else it is presentation only, and a
        ! comment further down says so.
        call env_value("PARQUET_FORTRAN_THREADS", text, got)
        if (got) then
            call env_int32("PARQUET_FORTRAN_THREADS", text, n32)
            call parquet_set_threads(n32)
        end if
        ! The rest in parquet_print_settings' order, so the sequence and the dump read side by side.
        ! The order is NOT load-bearing anywhere, including for the compression pair, which looks
        ! like it should be: parquet_resolve_writer_compression reads cfg_default_compression and
        ! cfg_default_compression_level together at writer-open time, so neither setter disturbs the
        ! other and storing them either way round gives the same result. Verified by mutation --
        ! swapping the two changes no test. Keep the order anyway, for readability, but do not add a
        ! comment claiming a dependency that is not there.
        call env_value("PARQUET_FORTRAN_ARROW_THREADS", text, got)
        if (got) then
            call env_int32("PARQUET_FORTRAN_ARROW_THREADS", text, n32)
            call parquet_set_arrow_threads(n32)
        end if
        call env_value("PARQUET_FORTRAN_SORT_THREADS", text, got)
        if (got) then
            call env_int32("PARQUET_FORTRAN_SORT_THREADS", text, n32)
            call parquet_set_sort_threads(n32)
        end if
        call env_value("PARQUET_FORTRAN_PREFETCH_THREADS", text, got)
        if (got) then
            call env_int32("PARQUET_FORTRAN_PREFETCH_THREADS", text, n32)
            call parquet_set_prefetch_threads(n32)
        end if
        call env_value("PARQUET_FORTRAN_TABLE_THREADS", text, got)
        if (got) then
            call env_int32("PARQUET_FORTRAN_TABLE_THREADS", text, n32)
            call parquet_set_table_threads(n32)
        end if
        call env_value("PARQUET_FORTRAN_STRING_THREADS", text, got)
        if (got) then
            call env_int32("PARQUET_FORTRAN_STRING_THREADS", text, n32)
            call parquet_set_string_threads(n32)
        end if

        call env_value("PARQUET_FORTRAN_RANDOM_THREADS", text, got)
        if (got) then
            call env_int32("PARQUET_FORTRAN_RANDOM_THREADS", text, n32)
            call parquet_set_random_threads(n32)
        end if

        call env_value("PARQUET_FORTRAN_RANDOM_PARALLEL_MIN_ELEMENTS", text, got)
        if (got) then
            call env_int64("PARQUET_FORTRAN_RANDOM_PARALLEL_MIN_ELEMENTS", text, n64)
            call parquet_set_random_parallel_min_elements(n64)
        end if
        call env_value("PARQUET_FORTRAN_SORT_COUNTING_PATH", text, got)
        if (got) then
            call env_logical("PARQUET_FORTRAN_SORT_COUNTING_PATH", text, flag)
            call parquet_set_sort_counting_path(flag)
        end if
        call env_value("PARQUET_FORTRAN_SORT_RADIX_PATH", text, got)
        if (got) then
            call env_logical("PARQUET_FORTRAN_SORT_RADIX_PATH", text, flag)
            call parquet_set_sort_radix_path(flag)
        end if
        call env_value("PARQUET_FORTRAN_SORT_COUNTING_BUCKET_LIMIT", text, got)
        if (got) then
            call env_int64("PARQUET_FORTRAN_SORT_COUNTING_BUCKET_LIMIT", text, n64)
            call parquet_set_sort_counting_bucket_limit(n64)
        end if
        call env_value("PARQUET_FORTRAN_DEFAULT_COMPRESSION", text, got)
        if (got) then
            call env_require_token("PARQUET_FORTRAN_DEFAULT_COMPRESSION", text, &
                parquet_valid_compressions, "compression codec")
            call parquet_set_default_compression(text)
        end if
        call env_value("PARQUET_FORTRAN_DEFAULT_COMPRESSION_LEVEL", text, got)
        if (got) then
            call env_int32("PARQUET_FORTRAN_DEFAULT_COMPRESSION_LEVEL", text, n32)
            call parquet_set_default_compression_level(n32)
        end if
        call env_value("PARQUET_FORTRAN_DEFAULT_USE_THREADS", text, got)
        if (got) then
            call env_logical("PARQUET_FORTRAN_DEFAULT_USE_THREADS", text, flag)
            call parquet_set_default_use_threads(flag)
        end if
        call env_value("PARQUET_FORTRAN_TARGET_ROW_GROUP_BYTES", text, got)
        if (got) then
            call env_int64("PARQUET_FORTRAN_TARGET_ROW_GROUP_BYTES", text, n64)
            call parquet_set_target_row_group_bytes(n64)
        end if
        call env_value("PARQUET_FORTRAN_STATISTICS_PRESCREEN", text, got)
        if (got) then
            call env_logical("PARQUET_FORTRAN_STATISTICS_PRESCREEN", text, flag)
            call parquet_set_statistics_prescreen(flag)
        end if
        call env_value("PARQUET_FORTRAN_VERBOSITY", text, got)
        if (got) then
            call env_require_token("PARQUET_FORTRAN_VERBOSITY", text, verbosity_tokens, "verbosity level")
            call parquet_set_verbosity(text)
        end if
        call env_value("PARQUET_FORTRAN_FILE_DATE", text, got)
        if (got) call parquet_set_file_date(text)
        call env_value("PARQUET_FORTRAN_MESSAGE_STREAM", text, got)
        if (got) then
            call env_require_token("PARQUET_FORTRAN_MESSAGE_STREAM", text, stream_tokens, "message stream")
            call parquet_set_message_stream(text)
        end if
    end subroutine parquet_settings_from_env