Table Of Contents

Source code for jdbc.iov2.steps.builtin

"""JDBC CreateTable step"""
import logging

import mitto.iov2.steps

from import INPUTTER

logger = logging.getLogger(__name__)

[docs]class CreateTable(mitto.iov2.steps.CreateTable): """Create a database table using SDL from a JDBC input. This class behaves identically to and can be interchanged with :class:`mitto.iov2.steps.builtin.CreateTable`, with one exception: This step should be used instead of :class:`mitto.iov2.steps.builtin.CreateTable` when the inputter used by the job is :class:`jdbc.iov2.input.Input` **and** the types of the output columns are to be based on the types returned by the JDBC `query`. In general, the output columns types are determined in the following manner: 1. If `reflect_sdl` is `True`, the SDL used by will be built from the JDBC cursor created when the `query` was executed. 2. If `reflect_sdl` is `False` or `None`, the SDL used to create output columns is determined in the following order: 1. If SDL is present in the environment, it will be used. 2. If SDL is not present in the environment, types will be learned from the data by Mitto's sampling facility. Parameters ---------- all See the base class above for documentation on parameters. Examples -------- Examples of using `CreateTable` as a step in a Mitto job configuration. .. code-block:: :caption: Example One -- default values "steps": [ ... { "use": "jdbc.iov2.steps.CreateTable" }, ... ] .. code-block:: :caption: Example Two -- override default values "steps": [ ... { "use": "jdbc.iov2.steps.CreateTable", "max_varchar_length": 16384, "batch_size": 10000 }, ... ] """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._handle_jdbc_sdl() def _handle_jdbc_sdl(self): """Add SDL from jdbc.iov2.input.Input query to environ if reflect_sdl is set""" inputter = self.environ[INPUTTER] if hasattr(inputter, "reflect_sdl"): # Inputter is jdbc.iov2.input.Input inputter.add_sdl_to_environ(self.environ)