Skip to content

Commit

Permalink
Fix new lines, change createResultSet back to taking in varags
Browse files Browse the repository at this point in the history
  • Loading branch information
olivrlee committed Sep 15, 2023
1 parent 1cb3b92 commit 8e7ba3c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ void init() {
}
return super.unwrap(iface);
}

@Override public CalciteStatement createStatement(int resultSetType,
int resultSetConcurrency, int resultSetHoldability) throws SQLException {
return (CalciteStatement) super.createStatement(resultSetType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.apache.calcite.avatica.MetaImpl.MetaColumn;
import org.apache.calcite.schema.Table;

import java.util.List;

/** Factory for creating MetaColumns for getColumns(). */
public interface CalciteMetaColumnFactory {
/** Instantiates a MetaColumn. */
Expand All @@ -43,7 +41,7 @@ MetaColumn newMetaColumn(
String isGeneratedcolumn);

/** Returns the list of expected column names. */
List<String> getColumnNames();
String[] getColumnNames();

/** Returns the class of MetaColumn that is created. */
Class<?> getMetaColumnClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,39 @@
import org.apache.calcite.avatica.MetaImpl.MetaColumn;
import org.apache.calcite.schema.Table;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/** Default implementation of CalciteMetaColumnFactoryImpl. */
public class CalciteMetaColumnFactoryImpl implements
CalciteMetaColumnFactory {

public static final CalciteMetaColumnFactoryImpl INSTANCE = new CalciteMetaColumnFactoryImpl();
public CalciteMetaColumnFactoryImpl() {};

public static final List<String> META_COLUMN_COLUMN_NAMES =
Collections.unmodifiableList(
Arrays.asList(
"TABLE_CAT",
"TABLE_SCHEM",
"TABLE_NAME",
"COLUMN_NAME",
"DATA_TYPE",
"TYPE_NAME",
"COLUMN_SIZE",
"BUFFER_LENGTH",
"DECIMAL_DIGITS",
"NUM_PREC_RADIX",
"NULLABLE",
"REMARKS",
"COLUMN_DEF",
"SQL_DATA_TYPE",
"SQL_DATETIME_SUB",
"CHAR_OCTET_LENGTH",
"ORDINAL_POSITION",
"IS_NULLABLE",
"SCOPE_CATALOG",
"SCOPE_SCHEMA",
"SCOPE_TABLE",
"SOURCE_DATA_TYPE",
"IS_AUTOINCREMENT",
"IS_GENERATEDCOLUMN"));
public static final String[] META_COLUMN_COLUMN_NAMES =
new String[] {
"TABLE_CAT",
"TABLE_SCHEM",
"TABLE_NAME",
"COLUMN_NAME",
"DATA_TYPE",
"TYPE_NAME",
"COLUMN_SIZE",
"BUFFER_LENGTH",
"DECIMAL_DIGITS",
"NUM_PREC_RADIX",
"NULLABLE",
"REMARKS",
"COLUMN_DEF",
"SQL_DATA_TYPE",
"SQL_DATETIME_SUB",
"CHAR_OCTET_LENGTH",
"ORDINAL_POSITION",
"IS_NULLABLE",
"SCOPE_CATALOG",
"SCOPE_SCHEMA",
"SCOPE_TABLE",
"SOURCE_DATA_TYPE",
"IS_AUTOINCREMENT",
"IS_GENERATEDCOLUMN"};

@Override public MetaColumn newMetaColumn(
Table table,
Expand Down Expand Up @@ -93,7 +88,7 @@ public class CalciteMetaColumnFactoryImpl implements
isGeneratedcolumn);
}

@Override public List<String> getColumnNames() {
@Override public String[] getColumnNames() {
return META_COLUMN_COLUMN_NAMES;
}

Expand Down
70 changes: 33 additions & 37 deletions core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -192,11 +191,11 @@ public static Pattern likeToRegex(Pat pattern) {
}

private <E> MetaResultSet createResultSet(Enumerable<E> enumerable,
Class clazz, List<String> names) {
assert names.size() > 0;
final List<ColumnMetaData> columns = new ArrayList<>(names.size());
final List<Field> fields = new ArrayList<>(names.size());
final List<String> fieldNames = new ArrayList<>(names.size());
Class clazz, String... names) {
requireNonNull(names, "names");
final List<ColumnMetaData> columns = new ArrayList<>(names.length);
final List<Field> fields = new ArrayList<>(names.length);
final List<String> fieldNames = new ArrayList<>(names.length);
for (String name : names) {
final int index = fields.size();
final String fieldName = AvaticaUtils.toCamelCase(name);
Expand Down Expand Up @@ -303,24 +302,24 @@ private static ImmutableMap.Builder<DatabaseProperty, Object> addProperty(
@Override public MetaResultSet getTypeInfo(ConnectionHandle ch) {
return createResultSet(allTypeInfo(),
MetaTypeInfo.class,
Arrays.asList("TYPE_NAME",
"DATA_TYPE",
"PRECISION",
"LITERAL_PREFIX",
"LITERAL_SUFFIX",
"CREATE_PARAMS",
"NULLABLE",
"CASE_SENSITIVE",
"SEARCHABLE",
"UNSIGNED_ATTRIBUTE",
"FIXED_PREC_SCALE",
"AUTO_INCREMENT",
"LOCAL_TYPE_NAME",
"MINIMUM_SCALE",
"MAXIMUM_SCALE",
"SQL_DATA_TYPE",
"SQL_DATETIME_SUB",
"NUM_PREC_RADIX"));
"TYPE_NAME",
"DATA_TYPE",
"PRECISION",
"LITERAL_PREFIX",
"LITERAL_SUFFIX",
"CREATE_PARAMS",
"NULLABLE",
"CASE_SENSITIVE",
"SEARCHABLE",
"UNSIGNED_ATTRIBUTE",
"FIXED_PREC_SCALE",
"AUTO_INCREMENT",
"LOCAL_TYPE_NAME",
"MINIMUM_SCALE",
"MAXIMUM_SCALE",
"SQL_DATA_TYPE",
"SQL_DATETIME_SUB",
"NUM_PREC_RADIX");
}

@Override public MetaResultSet getColumns(ConnectionHandle ch,
Expand Down Expand Up @@ -464,7 +463,6 @@ public Enumerable<MetaColumn> columns(final MetaTable table_) {
.map(RelDataType::getSqlTypeName)
.map(SqlTypeName::getJdbcOrdinal)
.orElse(field.getType().getSqlTypeName().getJdbcOrdinal());

return metaColumnFactory.newMetaColumn(
table.calciteTable,
table.tableCat,
Expand Down Expand Up @@ -498,21 +496,20 @@ public Enumerable<MetaColumn> columns(final MetaTable table_) {
final Predicate1<MetaSchema> schemaMatcher = namedMatcher(schemaPattern);
return createResultSet(schemas(catalog).where(schemaMatcher),
MetaSchema.class,
Arrays.asList(
"TABLE_SCHEM",
"TABLE_CATALOG"));
"TABLE_SCHEM",
"TABLE_CATALOG");
}

@Override public MetaResultSet getCatalogs(ConnectionHandle ch) {
return createResultSet(catalogs(),
MetaCatalog.class,
Arrays.asList("TABLE_CAT"));
"TABLE_CAT");
}

@Override public MetaResultSet getTableTypes(ConnectionHandle ch) {
return createResultSet(tableTypes(),
MetaTableType.class,
Arrays.asList("TABLE_TYPE"));
"TABLE_TYPE");
}

@Override public MetaResultSet getFunctions(ConnectionHandle ch,
Expand All @@ -527,13 +524,12 @@ public Enumerable<MetaColumn> columns(final MetaTable table_) {
(Comparable) FlatLists.of(
x.functionCat, x.functionSchem, x.functionName, x.specificName)),
MetaFunction.class,
Arrays.asList(
"FUNCTION_CAT",
"FUNCTION_SCHEM",
"FUNCTION_NAME",
"REMARKS",
"FUNCTION_TYPE",
"SPECIFIC_NAME"));
"FUNCTION_CAT",
"FUNCTION_SCHEM",
"FUNCTION_NAME",
"REMARKS",
"FUNCTION_TYPE",
"SPECIFIC_NAME");
}

Enumerable<MetaFunction> functions(final MetaSchema schema_, final String catalog) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
import org.apache.calcite.avatica.MetaImpl.MetaTable;
import org.apache.calcite.schema.Table;

import java.util.List;

/** Factory for creating MetaTables for getTables(). */
public interface CalciteMetaTableFactory {
/** Instantiates a MetaTable. */
MetaTable newMetaTable(Table table, String tableCat, String tableSchem, String tableName);

/** Returns the list of expected column names. */
List<String> getColumnNames();
String[] getColumnNames();

/** Returns the class of MetaTable that is created. */
Class<?> getMetaTableClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,15 @@
import org.apache.calcite.jdbc.CalciteMetaImpl.CalciteMetaTable;
import org.apache.calcite.schema.Table;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/** Default implementation of CalciteMetaTableFactory. */
public class CalciteMetaTableFactoryImpl implements
CalciteMetaTableFactory {

public static final CalciteMetaTableFactoryImpl INSTANCE = new CalciteMetaTableFactoryImpl();
public CalciteMetaTableFactoryImpl() {};

public static final List<String> META_TABLE_COLUMN_NAMES =
Collections.unmodifiableList(
Arrays.asList("TABLE_CAT",
public static final String[] META_TABLE_COLUMN_NAMES =
new String[] {"TABLE_CAT",
"TABLE_SCHEM",
"TABLE_NAME",
"TABLE_TYPE",
Expand All @@ -41,14 +36,14 @@ public class CalciteMetaTableFactoryImpl implements
"TYPE_SCHEM",
"TYPE_NAME",
"SELF_REFERENCING_COL_NAME",
"REF_GENERATION"));
"REF_GENERATION"};

@Override public CalciteMetaTable newMetaTable(Table table, String tableCat,
String tableSchem, String tableName) {
return new CalciteMetaTable(table, tableCat, tableSchem, tableName);
}

@Override public List<String> getColumnNames() {
@Override public String[] getColumnNames() {
return META_TABLE_COLUMN_NAMES;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.apache.calcite.test.CalciteAssert.that;

Expand Down Expand Up @@ -107,20 +104,19 @@ public static class MetaExtraTableFactoryImpl implements CalciteMetaTableFactory
return new MetaExtraTable(table, tableCat, tableSchem, tableName);
}

@Override public List<String> getColumnNames() {
return Collections.unmodifiableList(
Arrays.asList(
"TABLE_CAT",
"TABLE_SCHEM",
"TABLE_NAME",
"TABLE_TYPE",
"REMARKS",
"TYPE_CAT",
"TYPE_SCHEM",
"TYPE_NAME",
"SELF_REFERENCING_COL_NAME",
"REF_GENERATION",
"EXTRA_LABEL"));
@Override public String[] getColumnNames() {
return new String[] {
"TABLE_CAT",
"TABLE_SCHEM",
"TABLE_NAME",
"TABLE_TYPE",
"REMARKS",
"TYPE_CAT",
"TYPE_SCHEM",
"TYPE_NAME",
"SELF_REFERENCING_COL_NAME",
"REF_GENERATION",
"EXTRA_LABEL"};
}

@Override public Class<?> getMetaTableClass() {
Expand Down

0 comments on commit 8e7ba3c

Please sign in to comment.