Code Monkey home page Code Monkey logo

db-csv-loader's Introduction

Database CSV Loader

Solution Explanation

  • This is a cli application where user can pass mapping file and csv file to load data into database.
  • This is fully extensible since logic for insert data is extracted out to a yml file (mapping file) so that user can decide which data should be inserted.
  • In case of changing database, user can provide custom property file using -Dspring.config.location

####Mapping file Explanation

  • mapping section is having csv header value (csv-col), db-col(database column) and transformer class in order to do data transformation.
  • check-query is use for checking duplication
  • insert-query is use for inserting the data- Note: this query will be used for dynamically add data for batch insert.
mapping:
- csv-col: 'data'
  db-col: 'DATA'
  transformer: 'com.dulanja33.dcl.transformers.StringTransformer'
- csv-col: 'value'
  db-col: 'VALUE'
  transformer: 'com.dulanja33.dcl.transformers.IntegerTransformer'
- csv-col: 'date'
  db-col: 'DATE'
  transformer: 'com.dulanja33.dcl.transformers.StringTransformer'
check-query: 'select count(*) from TEST where DATA = ${data}'
insert-query: "insert into TEST(DATA,VALUE,DATE) values ${(${data},${value},str_to_date(${date},'%d.%m.%y'))}"

How to run

mvn clean install to build the jar then run following with values

java -jar db-csv-loader-0.0.1-SNAPSHOT.jar --mapping <absolute-path-to-mapping> --csv <absolute-path-to-csv> --chunkSize <number of data set for one insert>

Note: better give chunkSize 1 for given sales dataset since there are errors in csv

Assumption

  • Duplicate records based on table constraints are not inserting.
  • when chunkSize is given if any insertion fails then whole batch will be considered as fail.

db-csv-loader's People

Contributors

dulanja33 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.