From 3dd724554d8e2d86b44dc21a71363f80c23bd590 Mon Sep 17 00:00:00 2001 From: Colebow Date: Wed, 1 Mar 2023 14:29:26 -0800 Subject: [PATCH 1/2] Add redirects extension and memsql redirect --- docs/src/main/sphinx/conf.py | 11 +++- docs/src/main/sphinx/ext/redirects.py | 93 +++++++++++++++++++++++++++ docs/src/main/sphinx/redirects.txt | 1 + 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 docs/src/main/sphinx/ext/redirects.py create mode 100644 docs/src/main/sphinx/redirects.txt diff --git a/docs/src/main/sphinx/conf.py b/docs/src/main/sphinx/conf.py index 71c2574ab727..1322e8b61fd9 100644 --- a/docs/src/main/sphinx/conf.py +++ b/docs/src/main/sphinx/conf.py @@ -74,7 +74,16 @@ def setup(app): needs_sphinx = '3.0' -extensions = ['myst_parser', 'backquote', 'download', 'issue', 'sphinx_copybutton'] +extensions = [ + 'myst_parser', + 'backquote', + 'download', + 'issue', + 'sphinx_copybutton', + 'redirects', +] + +redirects_file = 'redirects.txt' templates_path = ['templates'] diff --git a/docs/src/main/sphinx/ext/redirects.py b/docs/src/main/sphinx/ext/redirects.py new file mode 100644 index 000000000000..f78b3c341275 --- /dev/null +++ b/docs/src/main/sphinx/ext/redirects.py @@ -0,0 +1,93 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Copyright (c) 2017 Stephen Finucane. +# Version 0.1.0 modified April 10, 2023 for Trino use. +# See https://github.com/sphinx-contrib/redirects/pull/6 + +import os + +from sphinx.builders import html as html_builder +from sphinx.builders import dirhtml as dirhtml_builder +from sphinx.util import logging + +logger = logging.getLogger(__name__) + +TEMPLATE = """ + + +""" + + +def generate_redirects(app): + + path = os.path.join(app.srcdir, app.config.redirects_file) + if not os.path.exists(path): + logger.info("Could not find redirects file at '%s'", path) + return + + if isinstance(app.config.source_suffix, dict): + in_suffixes = list(app.config.source_suffix) + else: + in_suffixes = app.config.source_suffix + + if not isinstance(app.builder, html_builder.StandaloneHTMLBuilder): + logger.warn( + "The 'sphinxcontib-redirects' plugin is only supported " + "for the 'html' and 'dirhtml' builder, but you are using '%s'. " + "Skipping...", type(app.builder) + ) + return + + from_suffix = to_suffix = '.html' + if type(app.builder) == dirhtml_builder.DirectoryHTMLBuilder: + from_suffix = '/index.html' + to_suffix = '/' + + with open(path) as redirects: + for line in redirects.readlines(): + from_path, to_path = line.rstrip().split(' ') + + logger.debug("Redirecting '%s' to '%s'", from_path, to_path) + + for in_suffix in in_suffixes: + if from_path.endswith(in_suffix): + from_path = from_path.replace(in_suffix, from_suffix) + to_path_prefix = ( + '..%s' + % os.path.sep + * (len(from_path.split(os.path.sep)) - 1) + ) + to_path = to_path_prefix + to_path.replace( + in_suffix, to_suffix + ) + + if not to_path: + raise Exception('failed to find input file!') + + redirected_filename = os.path.join(app.builder.outdir, from_path) + redirected_directory = os.path.dirname(redirected_filename) + if not os.path.exists(redirected_directory): + os.makedirs(redirected_directory) + + with open(redirected_filename, 'w') as f: + f.write(TEMPLATE % to_path) + + +def setup(app): + app.add_config_value('redirects_file', 'redirects', 'env') + app.connect('builder-inited', generate_redirects) + return { + 'parallel_read_safe': True, + 'parallel_write_safe': True, + } diff --git a/docs/src/main/sphinx/redirects.txt b/docs/src/main/sphinx/redirects.txt new file mode 100644 index 000000000000..615b54c8a6ec --- /dev/null +++ b/docs/src/main/sphinx/redirects.txt @@ -0,0 +1 @@ +connector/memsql.rst connector/singlestore.rst From e9f14e671f3f33fb0028df0ff9a70cdcce536828 Mon Sep 17 00:00:00 2001 From: Colebow Date: Wed, 22 Feb 2023 15:09:16 -0800 Subject: [PATCH 2/2] Rename MemSQL docs to SingleStore --- docs/src/main/sphinx/connector.rst | 2 +- docs/src/main/sphinx/connector/{memsql.rst => singlestore.rst} | 0 docs/src/main/sphinx/ext/redirects.py | 1 + docs/src/main/sphinx/release/release-326.rst | 2 +- docs/src/main/sphinx/release/release-334.rst | 2 +- 5 files changed, 4 insertions(+), 3 deletions(-) rename docs/src/main/sphinx/connector/{memsql.rst => singlestore.rst} (100%) diff --git a/docs/src/main/sphinx/connector.rst b/docs/src/main/sphinx/connector.rst index 302f64cf0f9f..021546d8abc5 100644 --- a/docs/src/main/sphinx/connector.rst +++ b/docs/src/main/sphinx/connector.rst @@ -38,7 +38,7 @@ from different data sources. Prometheus Redis Redshift - SingleStore + SingleStore SQL Server System Thrift diff --git a/docs/src/main/sphinx/connector/memsql.rst b/docs/src/main/sphinx/connector/singlestore.rst similarity index 100% rename from docs/src/main/sphinx/connector/memsql.rst rename to docs/src/main/sphinx/connector/singlestore.rst diff --git a/docs/src/main/sphinx/ext/redirects.py b/docs/src/main/sphinx/ext/redirects.py index f78b3c341275..126160824c5f 100644 --- a/docs/src/main/sphinx/ext/redirects.py +++ b/docs/src/main/sphinx/ext/redirects.py @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + # Copyright (c) 2017 Stephen Finucane. # Version 0.1.0 modified April 10, 2023 for Trino use. # See https://github.com/sphinx-contrib/redirects/pull/6 diff --git a/docs/src/main/sphinx/release/release-326.rst b/docs/src/main/sphinx/release/release-326.rst index 3207f2b9cac2..7796e4e3acce 100644 --- a/docs/src/main/sphinx/release/release-326.rst +++ b/docs/src/main/sphinx/release/release-326.rst @@ -8,7 +8,7 @@ General * Fix incorrect query results when query contains ``LEFT JOIN`` over ``UNNEST``. (:issue:`2097`) * Fix performance regression in queries involving ``JOIN``. (:issue:`2047`) * Fix accounting of semantic analysis time when queued queries are cancelled. (:issue:`2055`) -* Add :doc:`/connector/memsql`. (:issue:`1906`) +* Add :doc:`/connector/singlestore`. (:issue:`1906`) * Improve performance of ``INSERT`` and ``CREATE TABLE ... AS`` queries containing redundant ``ORDER BY`` clauses. (:issue:`2044`) * Improve performance when processing columns of ``map`` type. (:issue:`2015`) diff --git a/docs/src/main/sphinx/release/release-334.rst b/docs/src/main/sphinx/release/release-334.rst index 373e1dcfafff..09ed84949005 100644 --- a/docs/src/main/sphinx/release/release-334.rst +++ b/docs/src/main/sphinx/release/release-334.rst @@ -81,7 +81,7 @@ Hive connector MemSQL connector ---------------- -* Include :doc:`/connector/memsql` in the server tarball and RPM. (:issue:`3743`) +* Include :doc:`/connector/singlestore` in the server tarball and RPM. (:issue:`3743`) MongoDB connector -----------------