Created
          March 25, 2018 13:26 
        
      - 
      
 - 
        
Save tilakpatidar/2aa2d1c5f40303db12a358969fd6895a to your computer and use it in GitHub Desktop.  
    Finding unique records between ORC file and MySQL rows using Apache Spark
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import spark.implicits._ | |
| import org.apache.spark.sql.SaveMode | |
| val products = spark.sqlContext.read.format("jdbc").option("driver", "com.mysql.jdbc.Driver").option("dbtable", "products").option("user", "gobblin").option("password", "gobblin").option("url", "jdbc:mysql://localhost/mopar_demo").load() | |
| val newProducts = spark.sqlContext.read.format("orc").load("/Users/tilak/gobblin/mopar-demo/output/org/apache/gobblin/copy/user/tilak/pricing.products_1521799535.csv/20180325023900_append/part.task_PullCsvFromS3_1521945534992_0_0.orc") | |
| val newnewProducts = newProducts.except(products) | |
| val dfWriter = newnewProducts.write.mode(SaveMode.Append) | |
| val connectionProperties = new java.util.Properties() | |
| connectionProperties.setProperty("Driver", "com.mysql.jdbc.Driver") | |
| connectionProperties.setProperty("user", "root") | |
| connectionProperties.setProperty("password", "1") | |
| dfWriter.jdbc("jdbc:mysql://localhost/mopar_demo", "products", connectionProperties) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment