Example #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestDateSplits()
        {
            Statement s         = connection.CreateStatement();
            string    DateTable = "datetable";
            string    Col       = "foo";

            try
            {
                // delete the table if it already exists.
                s.ExecuteUpdate("DROP TABLE " + DateTable);
            }
            catch (SQLException)
            {
            }
            // Create the table.
            s.ExecuteUpdate("CREATE TABLE " + DateTable + "(" + Col + " DATE)");
            s.ExecuteUpdate("INSERT INTO " + DateTable + " VALUES('2010-04-01')");
            s.ExecuteUpdate("INSERT INTO " + DateTable + " VALUES('2010-04-02')");
            s.ExecuteUpdate("INSERT INTO " + DateTable + " VALUES('2010-05-01')");
            s.ExecuteUpdate("INSERT INTO " + DateTable + " VALUES('2011-04-01')");
            // commit this tx.
            connection.Commit();
            Configuration conf = new Configuration();

            conf.Set("fs.defaultFS", "file:///");
            FileSystem fs = FileSystem.GetLocal(conf);

            fs.Delete(new Path(OutDir), true);
            // now do a dd import
            Job job = Job.GetInstance(conf);

            job.SetMapperClass(typeof(TestDataDrivenDBInputFormat.ValMapper));
            job.SetReducerClass(typeof(Reducer));
            job.SetMapOutputKeyClass(typeof(TestDataDrivenDBInputFormat.DateCol));
            job.SetMapOutputValueClass(typeof(NullWritable));
            job.SetOutputKeyClass(typeof(TestDataDrivenDBInputFormat.DateCol));
            job.SetOutputValueClass(typeof(NullWritable));
            job.SetNumReduceTasks(1);
            job.GetConfiguration().SetInt("mapreduce.map.tasks", 2);
            FileOutputFormat.SetOutputPath(job, new Path(OutDir));
            DBConfiguration.ConfigureDB(job.GetConfiguration(), DriverClass, DbUrl, null, null
                                        );
            DataDrivenDBInputFormat.SetInput(job, typeof(TestDataDrivenDBInputFormat.DateCol)
                                             , DateTable, null, Col, Col);
            bool ret = job.WaitForCompletion(true);

            NUnit.Framework.Assert.IsTrue("job failed", ret);
            // Check to see that we imported as much as we thought we did.
            NUnit.Framework.Assert.AreEqual("Did not get all the records", 4, job.GetCounters
                                                ().FindCounter(TaskCounter.ReduceOutputRecords).GetValue());
        }