Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.
*/
package com.aliyun.odps.jdbc;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.RowIdLifetime;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import com.aliyun.odps.Column;
import com.aliyun.odps.Function;
import com.aliyun.odps.OdpsException;
import com.aliyun.odps.Table;
import com.aliyun.odps.account.AliyunAccount;
import com.aliyun.odps.jdbc.utils.JdbcColumn;
import com.aliyun.odps.jdbc.utils.OdpsLogger;
import com.aliyun.odps.jdbc.utils.Utils;
import com.aliyun.odps.type.TypeInfo;
import com.aliyun.odps.type.TypeInfoFactory;
import com.aliyun.odps.utils.StringUtils;
public class OdpsDatabaseMetaData extends WrapperAdapter implements DatabaseMetaData {
private final OdpsLogger log;
private static final String PRODUCT_NAME = "MaxCompute/ODPS";
private static final String DRIVER_NAME = "odps-jdbc";
private static final String SCHEMA_TERM = "project";
private static final String CATALOG_TERM = "project";
private static final String PROCEDURE_TERM = "N/A";
// Table types
public static final String TABLE_TYPE_TABLE = "TABLE";
public static final String TABLE_TYPE_VIEW = "VIEW";
// Column names
public static final String COL_NAME_TABLE_CAT = "TABLE_CAT";
public static final String COL_NAME_TABLE_CATALOG = "TABLE_CATALOG";
public static final String COL_NAME_TABLE_SCHEM = "TABLE_SCHEM";
public static final String COL_NAME_TABLE_NAME = "TABLE_NAME";
public static final String COL_NAME_TABLE_TYPE = "TABLE_TYPE";
public static final String COL_NAME_REMARKS = "REMARKS";
public static final String COL_NAME_TYPE_CAT = "TYPE_CAT";
public static final String COL_NAME_TYPE_SCHEM = "TYPE_SCHEM";
public static final String COL_NAME_TYPE_NAME = "TYPE_NAME";
public static final String COL_NAME_SELF_REFERENCING_COL_NAME = "SELF_REFERENCING_COL_NAME";
public static final String COL_NAME_REF_GENERATION = "REF_GENERATION";
// MaxCompute public data set project
public static final String PRJ_NAME_MAXCOMPUTE_PUBLIC_DATA = "MAXCOMPUTE_PUBLIC_DATA";
private static final int TABLE_NAME_LENGTH = 128;
private OdpsConnection conn;
OdpsDatabaseMetaData(OdpsConnection conn) {
this.conn = conn;
this.log = conn.log;
}
@Override
public boolean allProceduresAreCallable() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean allTablesAreSelectable() throws SQLException {
return true;
}
@Override
public String getURL() throws SQLException {
return conn.getOdps().getEndpoint();
}
@Override
public String getUserName() throws SQLException {
AliyunAccount account = (AliyunAccount) conn.getOdps().getAccount();
return account.getAccessId();
}
@Override
public boolean isReadOnly() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean nullsAreSortedHigh() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean nullsAreSortedLow() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean nullsAreSortedAtStart() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean nullsAreSortedAtEnd() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public String getDatabaseProductName() throws SQLException {
return PRODUCT_NAME;
}
@Override
public String getDatabaseProductVersion() throws SQLException {
return Utils.retrieveVersion("sdk.version");
}
@Override
public String getDriverName() throws SQLException {
return DRIVER_NAME;
}
@Override
public String getDriverVersion() throws SQLException {
return Utils.retrieveVersion("driver.version");
}
@Override
public int getDriverMajorVersion() {
try {
return Integer.parseInt(Utils.retrieveVersion("driver.version").split("\\.")[0]);
} catch (Exception e) {
e.printStackTrace();
return 1;
}
}
@Override
public int getDriverMinorVersion() {
try {
return Integer.parseInt(Utils.retrieveVersion("driver.version").split("\\.")[1]);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
@Override
public boolean usesLocalFiles() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean usesLocalFilePerTable() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsMixedCaseIdentifiers() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean storesUpperCaseIdentifiers() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean storesLowerCaseIdentifiers() throws SQLException {
return true;
}
@Override
public boolean storesMixedCaseIdentifiers() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public String getIdentifierQuoteString() throws SQLException {
return "`";
}
@Override
public String getSQLKeywords() throws SQLException {
return "overwrite ";
}
@Override
public String getNumericFunctions() throws SQLException {
return " ";
}
@Override
public String getStringFunctions() throws SQLException {
return " ";
}
@Override
public String getSystemFunctions() throws SQLException {
return " ";
}
@Override
public String getTimeDateFunctions() throws SQLException {
return " ";
}
@Override
public String getSearchStringEscape() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public String getExtraNameCharacters() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsAlterTableWithAddColumn() throws SQLException {
return true;
}
@Override
public boolean supportsAlterTableWithDropColumn() throws SQLException {
return false;
}
@Override
public boolean supportsColumnAliasing() throws SQLException {
return true;
}
@Override
public boolean nullPlusNonNullIsNull() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsConvert() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsConvert(int fromType, int toType) throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsTableCorrelationNames() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsDifferentTableCorrelationNames() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsExpressionsInOrderBy() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsOrderByUnrelated() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsGroupBy() throws SQLException {
return true;
}
@Override
public boolean supportsGroupByUnrelated() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsGroupByBeyondSelect() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsLikeEscapeClause() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsMultipleResultSets() throws SQLException {
return false;
}
@Override
public boolean supportsMultipleTransactions() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsNonNullableColumns() throws SQLException {
return false;
}
@Override
public boolean supportsMinimumSQLGrammar() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsCoreSQLGrammar() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsExtendedSQLGrammar() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsANSI92EntryLevelSQL() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsANSI92IntermediateSQL() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsANSI92FullSQL() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsIntegrityEnhancementFacility() throws SQLException {
return false;
}
@Override
public boolean supportsOuterJoins() throws SQLException {
return true;
}
@Override
public boolean supportsFullOuterJoins() throws SQLException {
return true;
}
@Override
public boolean supportsLimitedOuterJoins() throws SQLException {
return true;
}
@Override
public String getSchemaTerm() throws SQLException {
return SCHEMA_TERM;
}
@Override
public String getProcedureTerm() throws SQLException {
return PROCEDURE_TERM;
}
@Override
public String getCatalogTerm() throws SQLException {
return CATALOG_TERM;
}
@Override
public boolean isCatalogAtStart() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public String getCatalogSeparator() throws SQLException {
return ".";
}
@Override
public boolean supportsSchemasInDataManipulation() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInProcedureCalls() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInTableDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInIndexDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsCatalogsInDataManipulation() throws SQLException {
return true;
}
@Override
public boolean supportsCatalogsInProcedureCalls() throws SQLException {
return true;
}
@Override
public boolean supportsCatalogsInTableDefinitions() throws SQLException {
return true;
}
@Override
public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
return true;
}
@Override
public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
return true;
}
@Override
public boolean supportsPositionedDelete() throws SQLException {
return false;
}
@Override
public boolean supportsPositionedUpdate() throws SQLException {
return false;
}
@Override
public boolean supportsSelectForUpdate() throws SQLException {
return false;
}
@Override
public boolean supportsStoredProcedures() throws SQLException {
return false;
}
@Override
public boolean supportsSubqueriesInComparisons() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsSubqueriesInExists() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsSubqueriesInIns() throws SQLException {
return false;
}
@Override
public boolean supportsSubqueriesInQuantifieds() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsCorrelatedSubqueries() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsUnion() throws SQLException {
return false;
}
@Override
public boolean supportsUnionAll() throws SQLException {
return true;
}
@Override
public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxBinaryLiteralLength() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxCharLiteralLength() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxColumnNameLength() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxColumnsInGroupBy() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxColumnsInIndex() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxColumnsInOrderBy() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxColumnsInSelect() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxColumnsInTable() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxConnections() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxCursorNameLength() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxIndexLength() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxSchemaNameLength() throws SQLException {
return 32;
}
@Override
public int getMaxProcedureNameLength() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxCatalogNameLength() throws SQLException {
return 32;
}
@Override
public int getMaxRowSize() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxStatementLength() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxStatements() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxTableNameLength() throws SQLException {
return TABLE_NAME_LENGTH;
}
@Override
public int getMaxTablesInSelect() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getMaxUserNameLength() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public int getDefaultTransactionIsolation() throws SQLException {
log.error(Thread.currentThread().getStackTrace()[1].getMethodName() + " is not supported!!!");
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean supportsTransactions() throws SQLException {
return false;
}
@Override
public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
return false;
}
@Override
public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException {
return false;
}
@Override
public boolean supportsDataManipulationTransactionsOnly() throws SQLException {
return false;
}
@Override
public boolean dataDefinitionCausesTransactionCommit() throws SQLException {
return false;
}
@Override
public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
return false;
}
@Override
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern)
throws SQLException {
// Return an empty result set
OdpsResultSetMetaData meta =
new OdpsResultSetMetaData(Arrays.asList("PROCEDURE_CAT", "PROCEDURE_SCHEM",
"PROCEDURE_NAME", "RESERVERD", "RESERVERD",
"RESERVERD", "REMARKS", "PROCEDURE_TYPE",
"SPECIFIC_NAME"),
Arrays.asList(TypeInfoFactory.STRING, TypeInfoFactory.STRING,
TypeInfoFactory.STRING, TypeInfoFactory.STRING,
TypeInfoFactory.STRING,
TypeInfoFactory.STRING, TypeInfoFactory.STRING,
TypeInfoFactory.BIGINT,
TypeInfoFactory.STRING));
return new OdpsStaticResultSet(getConnection(), meta);
}
@Override
public ResultSet getProcedureColumns(String catalog, String schemaPattern,
String procedureNamePattern, String columnNamePattern)
throws SQLException {
// Return an empty result set
OdpsResultSetMetaData meta =
new OdpsResultSetMetaData(Arrays.asList("STUPID_PLACEHOLDERS", "USELESS_PLACEHOLDER"),
Arrays.asList(TypeInfoFactory.STRING, TypeInfoFactory.STRING));
return new OdpsStaticResultSet(getConnection(), meta);
}
@Override
public ResultSet getTables(
String catalog,
String schemaPattern,
String tableNamePattern,
String[] types) throws SQLException {
long begin = System.currentTimeMillis();
List