Search code examples
hadoopsqoop

Adding column in sqoop import


While importing data from SQL through sqoop, Is it possible to add a new column and insert time stamp into that column?

Is it possible by any other ways before getting data into HDFS?


Solution

  • You may use --query parameter of sqoop command and add SQL function to get current timestamp in query.

    Example: To import stud table from MySQL having rollnum and name columns.

    sqoop import --connect jdbc:mysql://localhost:3306/test --driver com.mysql.jdbc.Driver --username root --query 'select name, rollnum, current_timestamp from stud where $CONDITIONS' --target-dir '/tmp/stud1' --split-by id 
    

    Note current_timestamp mysql function used in query.