Skip to content

Commit b560c83

Browse files
committed
refactor and fix issue where descriptions aren't showing
1 parent fe08d0b commit b560c83

8 files changed

+68
-138
lines changed

scripts/settings/arithmetic-functions.sql

Lines changed: 0 additions & 22 deletions
This file was deleted.

scripts/settings/array-functions.sql

Lines changed: 0 additions & 22 deletions
This file was deleted.

scripts/settings/autogenerate-settings.sh

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,15 @@ if ! $INSTALL_SUCCESS; then
224224
fi
225225

226226
# --- Auto-generate Settings Documentation ---
227-
# Source files are assumed to be present in the CWD ($tmp_dir) by copy-clickhouse-repo-docs
228227
echo "[$SCRIPT_NAME] Auto-generating settings markdown pages..."
229-
# $target_dir is the project root (clickhouse-docs)
230228

231-
sql_files_found=$(find "$SCRIPT_DIR" -maxdepth 1 -name '*.sql' -print -quit)
229+
# Process other SQL files first (non-function related)
230+
sql_files_found=$(find "$SCRIPT_DIR" -maxdepth 1 -name '*.sql' ! -name 'generate-functions.sql' -print -quit)
232231
if [ -z "$sql_files_found" ]; then
233-
echo "[$SCRIPT_NAME] Warning: No *.sql files found in $SCRIPT_DIR to process."
232+
echo "[$SCRIPT_NAME] Warning: No non-function *.sql files found in $SCRIPT_DIR to process."
234233
else
235234
for SQL_FILE in "$SCRIPT_DIR"/*.sql; do
236-
if [ -f "$SQL_FILE" ]; then
235+
if [ -f "$SQL_FILE" ] && [ "$(basename "$SQL_FILE")" != "generate-functions.sql" ]; then
237236
echo "[$SCRIPT_NAME] Processing SQL file: $SQL_FILE"
238237
# Run ClickHouse from CWD ($tmp_dir), passing absolute path to SQL file
239238
"$script_path" --queries-file "$SQL_FILE" || {
@@ -246,6 +245,39 @@ else
246245
done
247246
fi
248247

248+
# Generate function documentation using the consolidated SQL file
249+
FUNCTION_SQL_FILE="$SCRIPT_DIR/generate-functions.sql"
250+
if [ -f "$FUNCTION_SQL_FILE" ]; then
251+
echo "[$SCRIPT_NAME] Generating function documentation using consolidated SQL file..."
252+
253+
# Define function categories to process
254+
FUNCTION_CATEGORIES=("Arithmetic" "Arrays" "Bit" "Bitmap" "Comparison" "Conditional")
255+
256+
for CATEGORY in "${FUNCTION_CATEGORIES[@]}"; do
257+
echo "[$SCRIPT_NAME] Processing $CATEGORY functions..."
258+
"$script_path" --param_category="$CATEGORY" --queries-file "$FUNCTION_SQL_FILE" || {
259+
echo "[$SCRIPT_NAME] FATAL: Failed to execute queries for $CATEGORY functions.";
260+
echo "[$SCRIPT_NAME] Attempting to re-run with output:"
261+
"$script_path" --param_category="$CATEGORY" --queries-file "$FUNCTION_SQL_FILE"
262+
exit 1;
263+
}
264+
265+
# Rename the temporary output file to the correct name
266+
CATEGORY_LOWER=$(echo "$CATEGORY" | tr '[:upper:]' '[:lower:]')
267+
if [ -f "temp-functions.md" ]; then
268+
mv "temp-functions.md" "${CATEGORY_LOWER}-functions.md" || {
269+
echo "[$SCRIPT_NAME] Error: Failed to rename temp-functions.md to ${CATEGORY_LOWER}-functions.md"
270+
exit 1
271+
}
272+
echo "[$SCRIPT_NAME] Generated ${CATEGORY_LOWER}-functions.md"
273+
else
274+
echo "[$SCRIPT_NAME] Warning: temp-functions.md not found after processing $CATEGORY functions"
275+
fi
276+
done
277+
else
278+
echo "[$SCRIPT_NAME] Warning: Consolidated function SQL file not found at $FUNCTION_SQL_FILE"
279+
fi
280+
249281
# --- temporary sed replacements ---
250282
sed -i.bak \
251283
-e 's/Limit the max number of partitions that can be accessed in one query. <= 0 means unlimited./Limit the max number of partitions that can be accessed in one query. `<=` 0 means unlimited./g' \
@@ -314,7 +346,7 @@ done
314346
insert_src_files=(
315347
"experimental-beta-settings.md"
316348
"arithmetic-functions.md"
317-
"array-functions.md"
349+
"arrays-functions.md"
318350
"bit-functions.md"
319351
"bitmap-functions.md"
320352
"comparison-functions.md"

scripts/settings/bit-functions.sql

Lines changed: 0 additions & 22 deletions
This file was deleted.

scripts/settings/bitmap-functions.sql

Lines changed: 0 additions & 22 deletions
This file was deleted.

scripts/settings/comparison-functions.sql

Lines changed: 0 additions & 22 deletions
This file was deleted.

scripts/settings/conditional-functions.sql

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- Consolidated function documentation generator
2+
-- Usage: Pass the category as a parameter, e.g.:
3+
-- clickhouse --param_category='Arithmetic' --queries-file generate-functions.sql
4+
5+
WITH function_docs AS (
6+
SELECT
7+
name,
8+
description,
9+
introduced_in,
10+
syntax,
11+
arguments,
12+
returned_value,
13+
examples
14+
FROM system.functions
15+
WHERE categories = {category:String}
16+
ORDER BY name ASC
17+
)
18+
SELECT
19+
format(
20+
'{}{}{}{}{}{}{}',
21+
'## ' || name || ' ' || printf('{#%s}', name) || '\n\n',
22+
'Introduced in: v' || introduced_in || '\n\n',
23+
description || '\n\n',
24+
'**Syntax**\n\n' || printf('```sql\n%s\n```', syntax) || '\n\n',
25+
if(empty(arguments), '**Arguments**\n\n- None.\n', '**Arguments**\n\n' || arguments || '\n\n'),
26+
'**Returned value**\n\n' || trim(returned_value) || '\n\n',
27+
'**Examples**\n\n' || examples || '\n'
28+
)
29+
FROM function_docs
30+
INTO OUTFILE 'temp-functions.md' TRUNCATE FORMAT LineAsString

0 commit comments

Comments
 (0)