All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cdap.plugin.db.SchemaReader Maven / Gradle / Ivy

There is a newer version: 1.11.2
Show newest version
/*
 * Copyright © 2019 Cask Data, Inc.
 *
 * 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.
 */

package io.cdap.plugin.db;

import io.cdap.cdap.api.data.schema.Schema;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.List;

/**
 * Main Interface to read db specific types.
 */
public interface SchemaReader {

  /**
   * Given the result set, get the metadata of the result set and return
   * list of {@link io.cdap.cdap.api.data.schema.Schema.Field},
   * where name of the field is same as column name and type of the field is obtained using
   * {@link SchemaReader#getSchema(ResultSetMetaData, int)}
   *
   * @param resultSet result set of executed query
   * @return list of schema fields
   * @throws SQLException
   */
  List getSchemaFields(ResultSet resultSet) throws SQLException;

  /**
   * Given a sql metadata return schema type
   * @param metadata resultSet metadata
   * @param index column index
   * @return CDAP schema
   * @throws SQLException
   */
  Schema getSchema(ResultSetMetaData metadata, int index) throws SQLException;

  /**
   * Given a sql metadata indicates if sql column must be ignored and not included in the output schema. Thus we can
   * support different data types for Sink and Source plugins.
   * 

* For example, in MS SQL 'TIMESTAMP' is the synonym for the 'ROWVERSION' data type, values of which are * automatically generated and can not be inserted or updated. Therefore 'TIMESTAMP' can not be supported by Sink * plugin. 'TIMESTAMP' reported as non-nullable column by JDBC connector, so inferred schema will be also * non-nullable for this field, requiring to set a value. By ignoring this column we will avoid schema validation * failure. * @param metadata resultSet metadata * @param index sql column index * @return 'true' if sql column must not included in the output schema, 'false' otherwise * @throws SQLException */ boolean shouldIgnoreColumn(ResultSetMetaData metadata, int index) throws SQLException; }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy