Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve functions reference #1049

Merged
merged 15 commits into from
Jul 10, 2024
Merged
77 changes: 77 additions & 0 deletions docs/misc/update_functions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/ruby
## A script to update functions in nightly references
## Usage: ruby misc/update_functions.rb [nightly | v0.x]
# encoding: utf-8
require 'net/http'
require 'rdoc'
killme2008 marked this conversation as resolved.
Show resolved Hide resolved

scalar_functions = {
:name => "DataFusion Scalar Functions",
:url => "https://raw.githubusercontent.com/apache/datafusion/main/docs/source/user-guide/sql/scalar_functions.md"
}
agg_functions = {
:name => "DataFusion Aggregate Functions",
:url => "https://raw.githubusercontent.com/apache/datafusion/main/docs/source/user-guide/sql/aggregate_functions.md"
}
window_functions = {
:name => "DataFusion Window Functions",
:url => "https://raw.githubusercontent.com/apache/datafusion/main/docs/source/user-guide/sql/window_functions.md"
}

## Apache DataFusion functions
datafusion_functions = [scalar_functions, agg_functions, window_functions]


File.open("temp.md", "w") do |f|
f.puts("# DataFusion Functions")
f.puts("This page is generated from the Apache DataFusion project's documents:")

for doc in datafusion_functions
name = doc[:name]
url = doc[:url]
markdown = " * [#{name}](#{url})"
f.puts markdown
end

f.puts

for doc in datafusion_functions
uri = URI(doc[:url])
markdown = Net::HTTP.get(uri).force_encoding(Encoding::UTF_8)

lines = markdown.split(/\n/)
lines.map! do |line|
## Add a level of headlines
if line =~ /^\s*(#+)\s/
replacement = "#{$1}#"

if replacement.length >= 4
replacement += "#"
end
line.gsub! $1, replacement
end
## Fix link: #a_b_c -> #a-b-c
if line =~ /(#[a-zA-Z0-9_]+)\)/
link = $1.to_s
replacement = link.gsub("_", "-")
line.gsub! link, replacement
end
## Fix link: a_b_c.md -> #a-b-c
if line =~ /\]\(([a-zA-Z0-9_]+\.md)\)/
link = $1.to_s
replacement = "#" + link.gsub("_", "-").gsub("\.md", "")
line.gsub! link, replacement
end
killme2008 marked this conversation as resolved.
Show resolved Hide resolved

line
end

f.puts lines.join("\n")
end
end

target = ARGV[0] || "nightly"

File.rename "temp.md", "#{target}/en/reference/sql/df_functions.md"

puts "#{target}/en/reference/sql/df_functions.md updated!"
Loading
Loading