From cbb02c6dc087fa7b15272784f8e69ff201d8c533 Mon Sep 17 00:00:00 2001 From: Oliver Lee Date: Fri, 4 Aug 2023 20:27:58 +0000 Subject: [PATCH] Reorder columns and add javadoc --- .../apache/calcite/jdbc/CalciteMetaImpl.java | 10 ++-- .../java/org/apache/calcite/schema/Table.java | 3 ++ .../calcite/jdbc/CalciteRemoteDriverTest.java | 30 +++++------ sqlline_edited | 54 +++++++++++++++++++ 4 files changed, 77 insertions(+), 20 deletions(-) create mode 100755 sqlline_edited diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java index 3733b6bd989..9d1b13ad38c 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java @@ -346,21 +346,21 @@ private static ImmutableMap.Builder addProperty( "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT", "IS_GENERATEDCOLUMN", + "LOOKER_FIELD_ALIAS", + "LOOKER_FIELD_CATEGORY", "LOOKER_FIELD_DESCRIPTION", + "LOOKER_FIELD_GROUP_VARIANT", "LOOKER_FIELD_LABEL", "LOOKER_FIELD_NAME", + "LOOKER_TYPE", + "LOOKER_USE_STRICT_VALUE_FORMAT", "LOOKER_VIEW_NAME", "LOOKER_VIEW_LABEL", "HIDDEN", - "LOOKER_FIELD_GROUP_VARIANT", "DIMENSION_GROUP", - "LOOKER_FIELD_CATEGORY", - "LOOKER_USE_STRICT_VALUE_FORMAT", "REQUIRES_REFRESH_ON_SORT", "SORTABLE", "VALUE_FORMAT", - "LOOKER_TYPE", - "LOOKER_FIELD_ALIAS", "TAGS", "FILTERS"); } diff --git a/core/src/main/java/org/apache/calcite/schema/Table.java b/core/src/main/java/org/apache/calcite/schema/Table.java index f3831eb4cd1..edb511446d3 100644 --- a/core/src/main/java/org/apache/calcite/schema/Table.java +++ b/core/src/main/java/org/apache/calcite/schema/Table.java @@ -96,6 +96,9 @@ default HashMap getTableMetadata() { return map; } + /** + * Gets Looker Field metadata if available. + */ default HashMap> getFieldMetadata() { HashMap> map = new HashMap<>(); return map; diff --git a/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java b/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java index c8a78108205..2540400f7b3 100644 --- a/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java +++ b/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java @@ -302,21 +302,21 @@ protected static Connection getRemoteConnection() throws SQLException { .getColumns(null, null, null, null); final ResultSetMetaData metaData = resultSet.getMetaData(); assertThat(metaData.getColumnCount(), is(41)); - assertThat(metaData.getColumnName(25), is("LOOKER_FIELD_DESCRIPTION")); - assertThat(metaData.getColumnName(26), is("LOOKER_FIELD_LABEL")); - assertThat(metaData.getColumnName(27), is("LOOKER_FIELD_NAME")); - assertThat(metaData.getColumnName(28), is("LOOKER_VIEW_NAME")); - assertThat(metaData.getColumnName(29), is("LOOKER_VIEW_LABEL")); - assertThat(metaData.getColumnName(30), is("HIDDEN")); - assertThat(metaData.getColumnName(31), is("LOOKER_FIELD_GROUP_VARIANT")); - assertThat(metaData.getColumnName(32), is("DIMENSION_GROUP")); - assertThat(metaData.getColumnName(33), is("LOOKER_FIELD_CATEGORY")); - assertThat(metaData.getColumnName(34), is("LOOKER_USE_STRICT_VALUE_FORMAT")); - assertThat(metaData.getColumnName(35), is("REQUIRES_REFRESH_ON_SORT")); - assertThat(metaData.getColumnName(36), is("SORTABLE")); - assertThat(metaData.getColumnName(37), is("VALUE_FORMAT")); - assertThat(metaData.getColumnName(38), is("LOOKER_TYPE")); - assertThat(metaData.getColumnName(39), is("LOOKER_FIELD_ALIAS")); + assertThat(metaData.getColumnName(25), is("LOOKER_FIELD_ALIAS")); + assertThat(metaData.getColumnName(26), is("LOOKER_FIELD_CATEGORY")); + assertThat(metaData.getColumnName(27), is("LOOKER_FIELD_DESCRIPTION")); + assertThat(metaData.getColumnName(28), is("LOOKER_FIELD_GROUP_VARIANT")); + assertThat(metaData.getColumnName(29), is("LOOKER_FIELD_LABEL")); + assertThat(metaData.getColumnName(30), is("LOOKER_FIELD_NAME")); + assertThat(metaData.getColumnName(31), is("LOOKER_TYPE")); + assertThat(metaData.getColumnName(32), is("LOOKER_USE_STRICT_VALUE_FORMAT")); + assertThat(metaData.getColumnName(33), is("LOOKER_VIEW_NAME")); + assertThat(metaData.getColumnName(34), is("LOOKER_VIEW_LABEL")); + assertThat(metaData.getColumnName(35), is("HIDDEN")); + assertThat(metaData.getColumnName(36), is("DIMENSION_GROUP")); + assertThat(metaData.getColumnName(37), is("REQUIRES_REFRESH_ON_SORT")); + assertThat(metaData.getColumnName(38), is("SORTABLE")); + assertThat(metaData.getColumnName(39), is("VALUE_FORMAT")); assertThat(metaData.getColumnName(40), is("TAGS")); assertThat(metaData.getColumnName(41), is("FILTERS")); resultSet.close(); diff --git a/sqlline_edited b/sqlline_edited new file mode 100755 index 00000000000..b28d27ccb7d --- /dev/null +++ b/sqlline_edited @@ -0,0 +1,54 @@ +#!/bin/bash +# sqlline - Script to launch SQL shell +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to you 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. +# +# Example: +# $ ./sqlline +# sqlline> !connect jdbc:calcite: admin admin + +# The script updates the classpath on each execution, +# You might use CACHE_SQLLINE_CLASSPATH=Y environment variable to cache it +# To build classpath jar manually use ./gradlew buildSqllineClasspath + +# Deduce whether we are running cygwin +case $(uname -s) in +(CYGWIN*) cygwin=true;; +(*) cygwin=;; +esac + +# readlink in macOS resolves only links, and it returns empty results if the path points to a file +root=$0 +if [[ -L "$root" ]]; then + root=$(readlink "$root") +fi +root=$(cd "$(dirname "$root")"; pwd) + +CP=$root/build/libs/sqllineClasspath.jar + +if [ "x$CACHE_SQLLINE_CLASSPATH" != "xY" ] || [ ! -f "$CP" ]; then + $root/gradlew --console plain -q :buildSqllineClasspath +fi + +VM_OPTS= +if [ "$cygwin" ]; then + # Work around https://github.com/jline/jline2/issues/62 + VM_OPTS=-Djline.terminal=jline.UnixTerminal +fi + +export JAVA_OPTS=-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl + +exec java -Xmx1g $VM_OPTS $JAVA_OPTS -jar "/usr/local/google/home/oliverlee/.m2/repository/sqlline/sqlline/1.13.0-oliver-SNAPSHOT/sqlline-1.13.0-oliver-SNAPSHOT-jar-with-dependencies.jar" "$@"