@compiles(CopyFromCSV, 'sqlite')
def compile_from_csv_sqlite(element, compiler, **kwargs):
    if not find_executable('sqlite3'):
        raise MDNotImplementedError("Could not find sqlite executable")

    t = element.element
    if not element.header:
        csv = element.csv
    else:
        csv = Temp(CSV)('.%s' % uuid.uuid1())
        assert csv.has_header, \
            'SQLAlchemy element.header is True but CSV inferred no header'

        # write to a temporary file after skipping the first line
        chunksize = 1 << 24  # 16 MiB
        lineterminator = element.lineterminator.encode(element.encoding)
        with open(element.csv.path, 'rb') as f:
            with closing(mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)) as mf:
                index = mf.find(lineterminator)
                if index == -1:
                    raise ValueError("'%s' not found" % lineterminator)
                mf.seek(index + len(lineterminator))  # len because \r\n
                with open(csv.path, 'wb') as g:
                    for chunk in iter(partial(mf.read, chunksize), b''):
                        g.write(chunk)

    fullpath = os.path.abspath(csv.path).encode('unicode-escape').decode()
    cmd = ['sqlite3',
           '-nullvalue', repr(element.na_value),
           '-separator', element.delimiter,
           '-cmd', '.import "%s" %s' % (
               # FIXME: format_table(t) is correct, but sqlite will complain
               fullpath, compiler.preparer.format_table(t)
           ),
           element.bind.url.database]
    stderr = subprocess.check_output(
        cmd,
        stderr=subprocess.STDOUT,
        stdin=subprocess.PIPE
    ).decode(sys.getfilesystemencoding())
    if stderr:
        # TODO: this seems like a lot of rigamarole
        try:
            raise OSError(stderr)
        except OSError as e:
            raise sa.exc.DatabaseError(' '.join(cmd), [], e)
    return ''
dataset/ETHPy150Open blaze/odo/odo/backends/sql_csv.py/compile_from_csv_sqlite/original