Github user jihoonson commented on a diff in the pull request:

    https://github.com/apache/tajo/pull/719#discussion_r38726773
  
    --- Diff: 
tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/JdbcMetadataProviderBase.java
 ---
    @@ -0,0 +1,253 @@
    +/*
    + * 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 org.apache.tajo.storage.jdbc;
    +
    +import com.google.common.base.Function;
    +import com.google.common.collect.Collections2;
    +import com.google.common.collect.Lists;
    +import org.apache.commons.logging.Log;
    +import org.apache.commons.logging.LogFactory;
    +import org.apache.tajo.catalog.*;
    +import org.apache.tajo.catalog.statistics.TableStats;
    +import org.apache.tajo.common.TajoDataTypes.Type;
    +import org.apache.tajo.exception.*;
    +import org.apache.tajo.util.KeyValueSet;
    +import org.apache.tajo.util.Pair;
    +
    +import javax.annotation.Nullable;
    +import java.net.URI;
    +import java.sql.*;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.Comparator;
    +import java.util.List;
    +
    +import static org.apache.tajo.catalog.CatalogUtil.newSimpleDataType;
    +
    +public abstract class JdbcMetadataProviderBase implements MetadataProvider 
{
    +  protected static final Log LOG = 
LogFactory.getLog(JdbcMetadataProviderBase.class);
    +
    +  protected final JdbcTablespace space;
    +  protected final String databaseName;
    +
    +  protected final String jdbcUri;
    +  protected final String username;
    +  protected final String password;
    +
    +  protected final Connection connection;
    +
    +  public JdbcMetadataProviderBase(JdbcTablespace space, String dbName) {
    +    this.space = space;
    +    this.databaseName = dbName;
    +
    +    ConnectionInfo connInfo = ConnectionInfo.fromURI(space.getUri());
    +    this.jdbcUri  = space.getUri().toASCIIString();
    +    this.username = connInfo.user();
    +    this.password = connInfo.password();
    +
    +    try {
    +      Class.forName(getJdbcDriverName()).newInstance();
    +      LOG.info(getJdbcDriverName() + " is loaded...");
    +    } catch (Exception e) {
    +      throw new TajoInternalError(e);
    +    }
    +
    +    try {
    +      connection = DriverManager.getConnection(jdbcUri, this.username, 
this.password);
    +    } catch (SQLException e) {
    +      throw new TajoInternalError(e);
    +    }
    +  }
    +
    +  @Override
    +  public String getTablespaceName() {
    +    return space.getName();
    +  }
    +
    +  @Override
    +  public URI getTablespaceUri() {
    +    return space.getUri();
    +  }
    +
    +  @Override
    +  public String getDatabaseName() {
    +    return databaseName;
    +  }
    +
    +  @Override
    +  public Collection<String> getSchemas() {
    +    return Collections.EMPTY_SET;
    +  }
    +
    +  @Override
    +  public Collection<String> getTables(@Nullable String schemaPattern, 
@Nullable String tablePattern) {
    +    ResultSet res = null;
    +    List<String> tableNames = Lists.newArrayList();
    +    try {
    +      res = connection.getMetaData().getTables(databaseName, 
schemaPattern, tablePattern, null);
    +      while(res.next()) {
    +        tableNames.add(res.getString("TABLE_NAME"));
    +      }
    +    } catch (SQLException e) {
    +      throw new TajoInternalError(e);
    +    } finally {
    +      try {
    +        if (res != null) {
    +          res.close();
    +        }
    +      } catch (SQLException e) {
    +        LOG.warn(e);
    +      }
    +    }
    +
    +    return tableNames;
    +  }
    +
    +  private TypeDesc convertDataType(ResultSet res) throws SQLException {
    +    final int typeId = res.getInt("DATA_TYPE");
    +
    +    switch (typeId ) {
    +    case Types.BOOLEAN:
    +      return new TypeDesc(newSimpleDataType(Type.BOOLEAN));
    --- End diff --
    
    This conversion code currently looks good, but should be improved later to 
support various types of database systems.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to