Example #1
0
 static long GetJobID(string jobname)
 {
     string[] lines = Exec.Shell("qizmt ps").Split('\r');
     for (int i = 0; i < lines.Length; i++)
     {
         string line = lines[i].Trim();
         if (line.IndexOf(jobname, StringComparison.OrdinalIgnoreCase) > -1)
         {
             int  del   = line.IndexOf(' ');
             long jobid = long.Parse(line.Substring(0, del));
             return(jobid);
         }
     }
     return(-1);
 }
Example #2
0
        public static void ShellCmdLossless()
        {
            {
                string guid = "{FFA94574-D63F-44ae-920E-5DFA841F6A69}";
                while (guid.Length < 300)
                {
                    guid += "a";
                }

                string job = (@"<SourceCode>
      <Jobs>
        <Job Name=`` Custodian=`` Email=``>
          <IOSettings>
            <JobType>local</JobType>
          </IOSettings>
          <Local>
            <![CDATA[
                public virtual void Local()
                {                     
                    DSpace_Log(`" + guid + @"`);               
                }
            ]]>
          </Local>
        </Job>
      </Jobs>
    </SourceCode>").Replace('`', '"');

                string tempdir = @"\\" + System.Net.Dns.GetHostName() + @"\" + Environment.CurrentDirectory.Replace(':', '$') + @"\" + Guid.NewGuid().ToString().Replace("-", "");
                if (System.IO.Directory.Exists(tempdir))
                {
                    System.IO.Directory.Delete(tempdir, true);
                }
                System.IO.Directory.CreateDirectory(tempdir);
                string tempjobname = Guid.NewGuid().ToString();
                System.IO.File.WriteAllText(tempdir + @"\" + tempjobname, job);
                Exec.Shell("Qizmt importdir \"" + tempdir + "\"");

                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("DSpace_DataProvider");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "SHELL 'Qizmt exec " + tempjobname + "'";
                DbDataReader  reader = cmd.ExecuteReader();
                StringBuilder sb     = new StringBuilder();
                while (reader.Read())
                {
                    sb.Append(reader.GetString(0));
                }
                reader.Close();
                conn.Close();

                //Clean up
                Exec.Shell(@"Qizmt del " + tempjobname);
                System.IO.Directory.Delete(tempdir, true);

                if (sb.ToString().IndexOf(guid) == -1)
                {
                    throw new Exception("Shell command failed.  Not lossless.");
                }
            }

            {
                string expected = Exec.Shell("Qizmt ls");

                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("DSpace_DataProvider");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "SHELL 'Qizmt ls'";
                DbDataReader  reader = cmd.ExecuteReader();
                StringBuilder sb     = new StringBuilder();
                while (reader.Read())
                {
                    sb.Append(reader.GetString(0));
                }
                reader.Close();
                conn.Close();

                if (expected != sb.ToString())
                {
                    throw new Exception("Shell command failed.  Not lossless.");
                }
            }
        }
Example #3
0
        public static void RIndexKeepValueOrder()
        {
            string      tablenameSorted = "tblTestB026B487BC3D451eA055A4699EE5D36A";
            string      indexname       = "indB026B487BC3D451eA055A4699EE5D36A";
            List <long> testkeys        = new List <long>();

            testkeys.Add(0);             //lower bound
            testkeys.Add(9);             //upper bound
            for (long i = 1; i < 5; i++) //in between
            {
                testkeys.Add(i);
            }

            {
                Console.WriteLine("Creating data...");

                string job     = @"
<SourceCode>
  <Jobs>
    <Job Name=`Cleanup` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
        <!--<LocalHost>localhost</LocalHost>-->
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>RDBMS_DBCORE</Using>      
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                Shell(@`Qizmt del RegressionTest_RIndexKeepValueOrder_Input.txt`);
                Shell(@`Qizmt del RegressionTest_RIndexKeepValueOrder_Input.bin`);
                try
                {
                    System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);                
                    using (DbConnection conn = fact.CreateConnection())
                    {
                        conn.ConnectionString = `Data Source = localhost`;
                        conn.Open();
                        DbCommand cmd = conn.CreateCommand();
                        cmd.CommandText = `drop table tblTestB026B487BC3D451eA055A4699EE5D36A`;
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = `drop rindex indB026B487BC3D451eA055A4699EE5D36A`;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                }
                catch
                {
                    
                }                
            }
        ]]>
      </Local>
    </Job>
    <Job Name=`createdata` Custodian=`` Email=`` Description=`Create sample data`>
      <IOSettings>
        <JobType>remote</JobType>
        <DFS_IO>
          <DFSReader></DFSReader>
          <DFSWriter>dfs://RegressionTest_RIndexKeepValueOrder_Input.txt</DFSWriter>
        </DFS_IO>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>RDBMS_DBCORE</Using>      
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Remote>
        <![CDATA[
            public virtual void Remote(RemoteInputStream dfsinput, RemoteOutputStream dfsoutput)
            {
                dfsoutput.WriteLine(`x`);
            }
        ]]>
      </Remote>
    </Job>
    <Job Name=`createdata` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>int</KeyLength>
        <DFSInput>dfs://RegressionTest_RIndexKeepValueOrder_Input.txt</DFSInput>
        <DFSOutput>dfs://RegressionTest_RIndexKeepValueOrder_Input.bin@nInt,nLong,nchar(400)</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>RDBMS_DBCORE</Using>      
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {
                recordset rkey = recordset.Prepare();
                rkey.PutInt(1);
                output.Add(rkey, recordset.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                for(int i = 0; i < 10; i++)
                {
                    for(int s = 0; s < 50000; s++)
                    {
                        DbRecordset rout = DbRecordset.Prepare();
                        rout.PutInt(s);
                        rout.PutLong((long)i);
                        rout.PutString(`x`, 400);
                        output.Add(rout.ToByteSlice());
                    }       
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`createrindex` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>RDBMS_DBCORE</Using>      
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);
                
                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create table tblTestB026B487BC3D451eA055A4699EE5D36A (num1 int, num2 long, str char(400))`;
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = `insert into tblTestB026B487BC3D451eA055A4699EE5D36A bind 'dfs://RegressionTest_RIndexKeepValueOrder_Input.bin'`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }

                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create rindex indB026B487BC3D451eA055A4699EE5D36A from tblTestB026B487BC3D451eA055A4699EE5D36A keepvalueorder ON num2`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }         
        }
        ]]>
      </Local>
    </Job>   
  </Jobs>
</SourceCode>
".Replace('`', '"');
                string tempdir = @"\\" + System.Net.Dns.GetHostName() + @"\" + Environment.CurrentDirectory.Replace(':', '$') + @"\" + Guid.NewGuid().ToString().Replace("-", "");
                if (System.IO.Directory.Exists(tempdir))
                {
                    System.IO.Directory.Delete(tempdir, true);
                }
                System.IO.Directory.CreateDirectory(tempdir);
                string tempjobname = Guid.NewGuid().ToString();
                System.IO.File.WriteAllText(tempdir + @"\" + tempjobname, job);
                Exec.Shell("Qizmt importdir \"" + tempdir + "\"");
                Exec.Shell("dspace exec " + tempjobname);
                //Clean up
                Exec.Shell(@"Qizmt del " + tempjobname);
                System.IO.Directory.Delete(tempdir, true);
            }


            System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("DSpace_DataProvider");

            {
                Console.WriteLine("Querying data using RSELECT NOPOOL...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost; rindex=nopool";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();

                foreach (long key in testkeys)
                {
                    cmd.CommandText = "rselect * from " + indexname.ToUpper() + " where key = " + key.ToString();
                    DbDataReader reader = cmd.ExecuteReader();
                    int          order  = 0;
                    while (reader.Read())
                    {
                        int    num1 = reader.GetInt32(0);
                        long   num2 = reader.GetInt64(1);
                        string str  = reader.GetString(2);
                        if (order++ != num1)
                        {
                            throw new Exception("Expected num1 to be: " + order.ToString() + ", but " + num1.ToString() + " is returned instead.");
                        }
                        if (num2 != key)
                        {
                            throw new Exception("Expected key to be: " + key.ToString() + ", but " + num2.ToString() + " is returned instead.");
                        }
                    }
                    reader.Close();

                    if (order != 50000)
                    {
                        throw new Exception("Expected 50000 rows to be returned for key: " + key.ToString() + ", but only " + order.ToString() + " is returned.");
                    }
                }
                conn.Close();
                Console.WriteLine("RSelect NOPOOL completed.");
            }

            {
                Console.WriteLine("Querying data using RSELECT pooled and OR statements...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost; rindex=pooled";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                for (int ki = 0; ki < testkeys.Count; ki += 2)
                {
                    long key1 = testkeys[ki];
                    long key2 = testkeys[ki + 1];
                    cmd.CommandText = "rselect * from " + indexname.ToUpper() + " where key = " + key1.ToString() + " OR key = " + key2.ToString();
                    DbDataReader reader = cmd.ExecuteReader();
                    int          order1 = 0;
                    int          order2 = 0;
                    while (reader.Read())
                    {
                        int    num1 = reader.GetInt32(0);
                        long   num2 = reader.GetInt64(1);
                        string str  = reader.GetString(2);
                        if (num2 == key1)
                        {
                            if (order1++ != num1)
                            {
                                throw new Exception("Expected num1 to be: " + order1.ToString() + ", but " + num1.ToString() + " is returned instead.");
                            }
                        }
                        else if (num2 == key2)
                        {
                            if (order2++ != num1)
                            {
                                throw new Exception("Expected num1 to be: " + order2.ToString() + ", but " + num1.ToString() + " is returned instead.");
                            }
                        }
                        else
                        {
                            throw new Exception("Unexpected key is returned: " + num2.ToString());
                        }
                    }
                    reader.Close();

                    if (order1 != 50000)
                    {
                        throw new Exception("Expected 50000 rows to be returned for key: " + key1.ToString() + ", but only " + order1.ToString() + " is returned.");
                    }
                    if (order2 != 50000)
                    {
                        throw new Exception("Expected 50000 rows to be returned for key: " + key2.ToString() + ", but only " + order2.ToString() + " is returned.");
                    }
                }
                conn.Close();
                Console.WriteLine("RSelect POOL completed.");
            }

            {
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "drop table " + tablenameSorted;
                cmd.ExecuteNonQuery();
                cmd.CommandText = "drop rindex " + indexname.ToUpper();
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }
Example #4
0
        public static void RIndexOutlierRandom()
        {
            string guid            = Guid.NewGuid().ToString().Replace("-", "");
            string tablename       = "rselect_test_" + guid;
            string indexname       = guid + "apple";
            string indexname_order = guid + "order";

            string[] allhosts = null;
            {
                string[] installs = Exec.Shell("Qizmt slaveinstalls").Trim()
                                    .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                allhosts = new string[installs.Length];

                for (int ip = 0; ip < installs.Length; ip++)
                {
                    string[] parts = installs[ip].Split(' ');
                    allhosts[ip] = parts[0];
                }
            }

            System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("DSpace_DataProvider");

            {
                Console.WriteLine("Creating data, table, and index...");

                string job = (@"<SourceCode>
  <Jobs>
    <Job Name=`Cleanup_Previous_Data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                //Clean up previous data.
               Shell(@`Qizmt del data_Input" + guid + @"*`);
                Shell(@`Qizmt del data_Output" + guid + @"*`);   
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);

                using (DbConnection conn = fact.CreateConnection())
                {
                    try
                    {
                        conn.ConnectionString = `Data Source = localhost`;
                        conn.Open();
                        DbCommand cmd = conn.CreateCommand();
                        cmd.CommandText = `drop table " + tablename + @"`;
                        cmd.ExecuteNonQuery();  
                        cmd.CommandText = `drop rindex " + indexname + @"`;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                    catch
                    {

                    }
                }           
            }
        ]]>
      </Local>
    </Job>
    <Job Name=`data_CreateSampleData` Custodian=`` Email=`` Description=`Create sample data`>
      <IOSettings>
        <JobType>remote</JobType>
        <DFS_IO>
          <DFSReader></DFSReader>
          <DFSWriter>dfs://data_Input" + guid + @".txt</DFSWriter>
        </DFS_IO>
      </IOSettings>
      <Remote>
        <![CDATA[
            public virtual void Remote(RemoteInputStream dfsinput, RemoteOutputStream dfsoutput)
            {
                dfsoutput.WriteLine(`1`);
            }
        ]]>
      </Remote>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"1.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-2);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-2);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-2);
                    rkey.PutInt(3);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(5);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(5);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"2.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(5);
                    rkey.PutInt(3);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(5);
                    rkey.PutInt(4);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(10);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(10);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(10);
                    rkey.PutInt(3);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"3.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(19);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(19);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(20);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(20);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(20);
                    rkey.PutInt(3);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(20);
                    rkey.PutInt(4);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(20);
                    rkey.PutInt(5);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(20);
                    rkey.PutInt(6);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(21);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(21);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(30);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(30);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(30);
                    rkey.PutInt(3);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(30);
                    rkey.PutInt(4);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(30);
                    rkey.PutInt(5);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(30);
                    rkey.PutInt(6);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(30);
                    rkey.PutInt(7);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>   
    <Job Name=`Prepare_tblFriends_Table_Create_RIndex` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>RDBMS_DBCORE</Using>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                Shell(@`qizmt combine data_Output" + guid + @"1.bin data_Output" + guid + @"2.bin data_Output" + guid + @"3.bin +data_Output" + guid + @".bin`);
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);
                
                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create table " + tablename + @" (id int, rid int)`;
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = `insert into " + tablename + @" bind 'dfs://data_Output" + guid + @".bin'`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }

                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create rindex " + indexname + @" from " + tablename + @" pinmemoryHASH OUTLIER random 3 ON id`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }         
        }
        ]]>
      </Local>
    </Job>
  </Jobs>
</SourceCode>").Replace('`', '"');
                string tempdir = @"\\" + System.Net.Dns.GetHostName() + @"\" + Environment.CurrentDirectory.Replace(':', '$') + @"\" + Guid.NewGuid().ToString().Replace("-", "");
                if (System.IO.Directory.Exists(tempdir))
                {
                    System.IO.Directory.Delete(tempdir, true);
                }
                System.IO.Directory.CreateDirectory(tempdir);
                string tempjobname = Guid.NewGuid().ToString();
                System.IO.File.WriteAllText(tempdir + @"\" + tempjobname, job);

                Exec.Shell("Qizmt importdir \"" + tempdir + "\"");

                Exec.Shell("dspace exec " + tempjobname);

                //Clean up
                Exec.Shell(@"Qizmt del " + tempjobname);
                System.IO.Directory.Delete(tempdir, true);
            }

            {
                Console.WriteLine("RInsert/RDeleting rindex...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = " + string.Join(",", allhosts) + "; rindex=pooled";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText =
                    "rinsert into " + indexname + " values(22,1) where key = 22\0" +
                    "rinsert into " + indexname + " values(22,2) where key = 22\0" +
                    "rinsert into " + indexname + " values(22,3) where key = 22\0" +
                    "rinsert into " + indexname + " values(22,4) where key = 22\0" +
                    "rinsert into " + indexname + " values(21,3) where key = 21\0" +
                    "rinsert into " + indexname + " values(21,4) where key = 21\0" +
                    "rinsert into " + indexname + " values(21,5) where key = 21\0" +
                    "rdelete from " + indexname + " where key = 21 and rid = 4\0" +
                    "rdelete from " + indexname + " where key = 21 and rid = 5\0" +
                    "rinsert into " + indexname + " values(8,1) where key = 8\0" +
                    "rinsert into " + indexname + " values(8,2) where key = 8\0" +
                    "rinsert into " + indexname + " values(8,3) where key = 8\0" +
                    "rinsert into " + indexname + " values(8,4) where key = 8\0" +
                    "rinsert into " + indexname + " values(6,1) where key = 6\0" +
                    "rinsert into " + indexname + " values(6,2) where key = 6\0" +
                    "rinsert into " + indexname + " values(5,5) where key = 5\0" +
                    "rinsert into " + indexname + " values(5,6) where key = 5\0" +
                    "rinsert into " + indexname + " values(-2,4) where key = -2\0";
                cmd.ExecuteNonQuery();
                conn.Close();
            }

            {
                Console.WriteLine("RSelecting from rindex...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = " + string.Join(",", allhosts) + "; rindex=pooled";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "rselect * from " + indexname + " where key = -2 or key = 5 or key = 6 or key = 8 or key= 10 or key = 19 or key=20 or key = 21 or key = 22 or key=30";
                DbDataReader reader = cmd.ExecuteReader();
                int          cnt    = 0;
                Dictionary <int, List <int> > results = new Dictionary <int, List <int> >();
                while (reader.Read())
                {
                    int x = reader.GetInt32(0);
                    int y = reader.GetInt32(1);
                    if (!results.ContainsKey(x))
                    {
                        results.Add(x, new List <int>());
                    }
                    results[x].Add(y);
                }
                reader.Close();
                conn.Close();

                Dictionary <int, List <int> > expected = new Dictionary <int, List <int> >();
                expected.Add(-2, new List <int>());
                expected[-2].Add(1);
                expected[-2].Add(2);
                expected[-2].Add(3);
                expected[-2].Add(4);

                expected.Add(5, new List <int>());
                expected[5].Add(1);
                expected[5].Add(2);
                expected[5].Add(3);
                expected[5].Add(4);
                expected[5].Add(5);
                expected[5].Add(6);

                expected.Add(6, new List <int>());
                expected[6].Add(1);
                expected[6].Add(2);

                expected.Add(8, new List <int>());
                expected[8].Add(1);
                expected[8].Add(2);
                expected[8].Add(3);
                expected[8].Add(4);

                expected.Add(10, new List <int>());
                expected[10].Add(1);
                expected[10].Add(2);
                expected[10].Add(3);

                expected.Add(19, new List <int>());
                expected[19].Add(1);
                expected[19].Add(2);

                expected.Add(20, new List <int>());
                expected[20].Add(1);
                expected[20].Add(2);
                expected[20].Add(3);
                expected[20].Add(4);
                expected[20].Add(5);
                expected[20].Add(6);

                expected.Add(21, new List <int>());
                expected[21].Add(1);
                expected[21].Add(2);
                expected[21].Add(3);

                expected.Add(22, new List <int>());
                expected[22].Add(1);
                expected[22].Add(2);
                expected[22].Add(3);
                expected[22].Add(4);

                expected.Add(30, new List <int>());
                expected[30].Add(1);
                expected[30].Add(2);
                expected[30].Add(3);
                expected[30].Add(4);
                expected[30].Add(5);
                expected[30].Add(6);
                expected[30].Add(7);

                Dictionary <int, int> expectedValuesCount = new Dictionary <int, int>();
                expectedValuesCount.Add(-2, 3);
                expectedValuesCount.Add(5, 2 + 3);   //2 from first chunk and 3 from second chunk
                expectedValuesCount.Add(6, 2);
                expectedValuesCount.Add(8, 3);
                expectedValuesCount.Add(10, 3);
                expectedValuesCount.Add(19, 2);
                expectedValuesCount.Add(20, 3);
                expectedValuesCount.Add(21, 3);
                expectedValuesCount.Add(22, 3);
                expectedValuesCount.Add(30, 3);

                if (results.Count != expected.Count)
                {
                    throw new Exception("Expected " + expected.Count.ToString() + " keys to be returned.  But received " + results.Count.ToString() + " keys instead.");
                }

                foreach (int key in results.Keys)
                {
                    List <int> rvalues = results[key];
                    if (rvalues.Count != expectedValuesCount[key])
                    {
                        throw new Exception("Expected values count for key " + key.ToString() + " is " + expectedValuesCount[key].ToString() + ", but got " + rvalues.Count.ToString() + " instead.");
                    }

                    checkValues(expected[key], rvalues);
                }
            }

            {
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "drop table " + tablename;
                cmd.ExecuteNonQuery();
                cmd.CommandText = "drop rindex " + indexname;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }
Example #5
0
        public static void RIndexOnCharPinHash()
        {
            string    tablename           = "rselect_test_" + Guid.NewGuid().ToString().Replace("-", "");
            string    tablenameSorted_str = "rselect_test_sorted_str" + Guid.NewGuid().ToString().Replace("-", "");
            string    indexname_str       = Guid.NewGuid().ToString().Replace("-", "") + "apple";
            const int TESTSIZE            = 10;

            OneRow[] testrows = null;

            testrows = RIndexOnCharPinHash_PrepareSourceTable(tablename, TESTSIZE);

            System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("DSpace_DataProvider");

            //Key column = string.
            {
                Console.WriteLine("Sorting table by key column string...");

                string job     = @"
<SourceCode>
  <Jobs>
    <Job Name=""sort_Preprocessing"">
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                Shell(@""Qizmt del sort7104E99F-1421-408b-85DE-1819B6B1C23D_Output*"");
            }
        ]]>
      </Local>
    </Job>
    <Job Name=""sort"">
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>401</KeyLength>
        <DFSInput></DFSInput>
        <DFSOutput>dfs://sort7104E99F-1421-408b-85DE-1819B6B1C23D_Output@434</DFSOutput>
        <OutputMethod>sorted</OutputMethod>
      </IOSettings>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {
                byte[] buf = line.ToBytes();
                output.Add(ByteSlice.Prepare(line, 15, 401), line); 
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {                
                for(int i = 0; i < values.Length; i++)
                {  
                    output.Add(values[i].Value);
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
  </Jobs>
</SourceCode>";
                string tempdir = @"\\" + System.Net.Dns.GetHostName() + @"\" + Environment.CurrentDirectory.Replace(':', '$') + @"\" + Guid.NewGuid().ToString().Replace("-", "");
                if (System.IO.Directory.Exists(tempdir))
                {
                    System.IO.Directory.Delete(tempdir, true);
                }
                System.IO.Directory.CreateDirectory(tempdir);
                string tempjobname = Guid.NewGuid().ToString();
                System.IO.File.WriteAllText(tempdir + @"\" + tempjobname, job);
                Exec.Shell("Qizmt importdir \"" + tempdir + "\"");

                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                {
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "CREATE TABLE " + tablenameSorted_str + " (num1 INT, num2 DOUBLE, str CHAR(200), dt DATETIME, num3 LONG)";
                    cmd.ExecuteNonQuery();
                }
                conn.Close();

                Exec.Shell("dspace exec \"//Job[@Name='sort']/IOSettings/DFSInput=RDBMS_Table_" + tablename + "@434\" " + tempjobname);

                conn.Open();
                {
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "insert into " + tablenameSorted_str + " bind 'dfs://sort7104E99F-1421-408b-85DE-1819B6B1C23D_Output'";
                    cmd.ExecuteNonQuery();
                }
                conn.Close();

                Console.WriteLine("Table sorted by string");

                //Clean up
                Exec.Shell(@"Qizmt del " + tempjobname);
                System.IO.Directory.Delete(tempdir, true);
            }

            {
                Console.WriteLine("Creating RIndexes PINMEMORYHASH on key column = str...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "CREATE RINDEX " + indexname_str + " FROM " + tablenameSorted_str + " PINMEMORYHASH ON str";
                cmd.ExecuteNonQuery();
                conn.Close();
                Console.WriteLine("RIndexes created.");
            }

            Dictionary <string, List <OneRow> > expected = new Dictionary <string, List <OneRow> >();
            {
                Console.WriteLine("Querying data using SELECT...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                foreach (OneRow row in testrows)
                {
                    cmd.CommandText = "select * from " + tablenameSorted_str + " where str = '" + row.str.Replace("'", "''") + "'";
                    DbDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        OneRow r;
                        r.num1 = reader.GetInt32(0);
                        r.num2 = reader.GetDouble(1);
                        r.str  = reader.GetString(2);
                        r.dt   = reader.GetDateTime(3);
                        r.num3 = reader.GetInt64(4);
                        if (!expected.ContainsKey(r.str))
                        {
                            expected.Add(r.str, new List <OneRow>());
                        }
                        expected[r.str].Add(r);
                    }
                    reader.Close();
                }
                conn.Close();
                Console.WriteLine("SELECT completed.");
            }

            {
                Console.WriteLine("Querying data using RSELECT NOPOOL...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost; rindex=nopool";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                foreach (string key in expected.Keys)
                {
                    List <OneRow> results = new List <OneRow>();
                    cmd.CommandText = "rselect * from " + indexname_str.ToUpper() + " where key = '" + key.Replace("'", "''") + "'";
                    DbDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        OneRow r;
                        r.num1 = reader.GetInt32(0);
                        r.num2 = reader.GetDouble(1);
                        r.str  = reader.GetString(2);
                        r.dt   = reader.GetDateTime(3);
                        r.num3 = reader.GetInt64(4);
                        results.Add(r);
                    }
                    reader.Close();

                    //compare results
                    List <OneRow> xlist = expected[key];
                    if (xlist.Count != results.Count)
                    {
                        throw new Exception("Result count: " + results.Count.ToString() + " is different from that of expected: " + xlist.Count.ToString() + ".  Query= " + cmd.CommandText);
                    }
                    foreach (OneRow r in results)
                    {
                        bool found = false;
                        foreach (OneRow x in xlist)
                        {
                            if (r.num1 == x.num1 && r.num2 == x.num2 && r.num3 == x.num3 && r.str == x.str && r.dt == x.dt)
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            throw new Exception("RSelect returned a row which was not located in expected results. num2=" + r.num2.ToString() + " num3=" + r.num3.ToString() + ".  Query= " + cmd.CommandText);
                        }
                    }
                    foreach (OneRow x in xlist)
                    {
                        bool found = false;
                        foreach (OneRow r in results)
                        {
                            if (r.num1 == x.num1 && r.num2 == x.num2 && r.num3 == x.num3 && r.str == x.str && r.dt == x.dt)
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            throw new Exception("RSelect did not return an expected row. num2=" + x.num2.ToString() + " num3=" + x.num3.ToString() + ".  Query= " + cmd.CommandText);
                        }
                    }
                }
                conn.Close();
                Console.WriteLine("RSelect NOPOOL completed.");
            }

            {
                Console.WriteLine("Querying data using RSELECT POOL/OR");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost; rindex=pooled";
                conn.Open();
                DbCommand cmd     = conn.CreateCommand();
                string    whereor = "";
                foreach (string key in expected.Keys)
                {
                    if (whereor.Length > 0)
                    {
                        whereor += " OR ";
                    }
                    whereor += " key = '" + key.Replace("'", "''") + "' ";
                }

                {
                    Dictionary <string, List <OneRow> > results = new Dictionary <string, List <OneRow> >();
                    cmd.CommandText = "rselect * from " + indexname_str.ToUpper() + " where " + whereor;
                    DbDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        OneRow r;
                        r.num1 = reader.GetInt32(0);
                        r.num2 = reader.GetDouble(1);
                        r.str  = reader.GetString(2);
                        r.dt   = reader.GetDateTime(3);
                        r.num3 = reader.GetInt64(4);
                        if (!results.ContainsKey(r.str))
                        {
                            results.Add(r.str, new List <OneRow>());
                        }
                        results[r.str].Add(r);
                    }
                    reader.Close();

                    //compare results
                    foreach (string key in expected.Keys)
                    {
                        List <OneRow> xlist = expected[key];
                        if (xlist.Count != results[key].Count)
                        {
                            throw new Exception("Result count: " + results[key].Count.ToString() + " is different from that of expected: " + xlist.Count.ToString() + ". Key=" + key.ToString() + ".  Query:" + cmd.CommandText);
                        }
                        foreach (OneRow r in results[key])
                        {
                            bool found = false;
                            foreach (OneRow x in xlist)
                            {
                                if (r.num1 == x.num1 && r.num2 == x.num2 && r.num3 == x.num3 && r.str == x.str && r.dt == x.dt)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                throw new Exception("RSelect returned a row which was not located in expected results. num2=" + r.num2.ToString() + " num3=" + r.num3.ToString() + ". Key=" + key.ToString() + ".  Query:" + cmd.CommandText);
                            }
                        }
                        foreach (OneRow x in xlist)
                        {
                            bool found = false;
                            foreach (OneRow r in results[key])
                            {
                                if (r.num1 == x.num1 && r.num2 == x.num2 && r.num3 == x.num3 && r.str == x.str && r.dt == x.dt)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                throw new Exception("RSelect did not return an expected row. num2=" + x.num2.ToString() + " num3=" + x.num3.ToString() + ". Key=" + key.ToString() + ".  Query:" + cmd.CommandText);
                            }
                        }
                    }
                }
                conn.Close();
                Console.WriteLine("RSelect POOL/OR completed.");
            }


            {
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "drop table " + tablename;
                cmd.ExecuteNonQuery();
                cmd.CommandText = "drop table " + tablenameSorted_str;
                cmd.ExecuteNonQuery();
                cmd.CommandText = "drop rindex " + indexname_str;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }
Example #6
0
        public static void RIndexFailover()
        {
            {
                int      replicationFactor = 0;
                string[] lines             = Exec.Shell("Qizmt replicationview").Split('\n');
                for (int i = 0; i < lines.Length; i++)
                {
                    string line = lines[i].Trim();
                    if (line.Length > 0)
                    {
                        int del = line.LastIndexOf(' ');
                        replicationFactor = Int32.Parse(line.Substring(del + 1));
                        if (replicationFactor > 0)
                        {
                            break;
                        }
                    }
                }
                if (replicationFactor < 2)
                {
                    throw new Exception("Cannot run RIndexFailover regression test when replication factor is less than 2.");
                }
            }

            string guid            = Guid.NewGuid().ToString().Replace("-", "");
            string tablename       = "rselect_test_" + guid;
            string indexname       = guid + "apple";
            string indexname_order = guid + "order";

            string[] allhosts     = null;
            string   qizmtrootdir = "";

            {
                string[] installs = Exec.Shell("Qizmt slaveinstalls").Trim()
                                    .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                allhosts = new string[installs.Length];

                for (int ip = 0; ip < installs.Length; ip++)
                {
                    string[] parts       = installs[ip].Split(' ');
                    string   installpath = parts[1];
                    int      del         = installpath.IndexOf(@"\", 2);
                    qizmtrootdir = installpath.Substring(del + 1);
                    allhosts[ip] = parts[0];
                }
            }

            System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("DSpace_DataProvider");

            {
                Console.WriteLine("Creating data, table, and index...");

                string job = (@"<SourceCode>
  <Jobs>
    <Job Name=`Cleanup_Previous_Data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                //Clean up previous data.
               Shell(@`Qizmt del data_Input" + guid + @"*`);
                Shell(@`Qizmt del data_Output" + guid + @"*`);   
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);

                using (DbConnection conn = fact.CreateConnection())
                {
                    try
                    {
                        conn.ConnectionString = `Data Source = localhost`;
                        conn.Open();
                        DbCommand cmd = conn.CreateCommand();
                        cmd.CommandText = `drop table " + tablename + @"`;
                        cmd.ExecuteNonQuery();  
                        cmd.CommandText = `drop rindex " + indexname + @"`;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                    catch
                    {

                    }
                }           
            }
        ]]>
      </Local>
    </Job>
    <Job Name=`data_CreateSampleData` Custodian=`` Email=`` Description=`Create sample data`>
      <IOSettings>
        <JobType>remote</JobType>
        <DFS_IO>
          <DFSReader></DFSReader>
          <DFSWriter>dfs://data_Input" + guid + @".txt</DFSWriter>
        </DFS_IO>
      </IOSettings>
      <Remote>
        <![CDATA[
            public virtual void Remote(RemoteInputStream dfsinput, RemoteOutputStream dfsoutput)
            {
                dfsoutput.WriteLine(`1`);
            }
        ]]>
      </Remote>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"1.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(5);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(5);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"2.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(10);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(10);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(14);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"3.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(21);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(25);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(80);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(80);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"4.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(80);
                    rkey.PutInt(3);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(80);
                    rkey.PutInt(4);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(90);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(102);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`Prepare_tblFriends_Table_Create_RIndex` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>RDBMS_DBCORE</Using>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                Shell(@`qizmt combine data_Output" + guid + @"1.bin data_Output" + guid + @"2.bin data_Output" + guid + @"3.bin data_Output" + guid + @"4.bin +data_Output" + guid + @".bin`);
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);
                
                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create table " + tablename + @" (id int, rid int)`;
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = `insert into " + tablename + @" bind 'dfs://data_Output" + guid + @".bin'`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }

                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create rindex " + indexname + @" from " + tablename + @" pinmemoryHASH ON id`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }         
        }
        ]]>
      </Local>
    </Job>
  </Jobs>
</SourceCode>").Replace('`', '"');
                string tempdir = @"\\" + System.Net.Dns.GetHostName() + @"\" + Environment.CurrentDirectory.Replace(':', '$') + @"\" + Guid.NewGuid().ToString().Replace("-", "");
                if (System.IO.Directory.Exists(tempdir))
                {
                    System.IO.Directory.Delete(tempdir, true);
                }
                System.IO.Directory.CreateDirectory(tempdir);
                string tempjobname = Guid.NewGuid().ToString();
                System.IO.File.WriteAllText(tempdir + @"\" + tempjobname, job);

                Exec.Shell("Qizmt importdir \"" + tempdir + "\"");

                Exec.Shell("dspace exec " + tempjobname);

                //Clean up
                Exec.Shell(@"Qizmt del " + tempjobname);
                System.IO.Directory.Delete(tempdir, true);
            }

            string badhost = "";
            {
                string bulkget = @"\\" + System.Net.Dns.GetHostName() + @"\" + Environment.CurrentDirectory.Replace(':', '$') + @"\" + Guid.NewGuid().ToString().Replace("-", "");
                Exec.Shell("Qizmt bulkget " + bulkget + " RDBMS_Table_" + tablename);
                string[] lines = System.IO.File.ReadAllLines(bulkget);
                System.IO.File.Delete(bulkget);

                string[] parts = lines[0].Split(' ');
                badhost = parts[0].Split(';')[0];
            }

            {
                Console.WriteLine("RInsert/RDeleting rindex...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = " + string.Join(",", allhosts) + "; rindex=pooled";
                conn.Open();
                Console.WriteLine("Connection established");

                Console.WriteLine("Stopping protocol service on {0}...", badhost);
                string result = Exec.Shell(@"sc \\" + badhost + " stop QueryAnalyzer_Protocol", true); // Suppress error.
                Console.WriteLine(result);

                System.Threading.Thread.Sleep(1000 * 3);

                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText =
                    "rdelete from " + indexname + " where key = 80 and rid=1\0" +
                    "rdelete from " + indexname + " where key = 80 and rid=2\0" +
                    "rdelete from " + indexname + " where key = 80 and rid=3\0" +
                    "rdelete from " + indexname + " where key = 80 and rid=4\0" +
                    "rinsert into " + indexname + " values(10, 3) where key = 10\0" +
                    "rinsert into " + indexname + " values(10, 19) where key = 10\0" +
                    "rdelete from " + indexname + " where key = 10 and rid=19\0" +
                    "rinsert into " + indexname + " values(20, 1) where key = 20\0" +
                    "rinsert into " + indexname + " values(30, 1) where key = 30\0" +
                    "rinsert into " + indexname + " values(30, 2) where key = 30\0" +
                    "rinsert into " + indexname + " values(9, 1) where key = 9\0" +
                    "rinsert into " + indexname + " values(9, 2) where key = 9\0" +
                    "rinsert into " + indexname + " values(99, 1) where key = 99\0" +
                    "rdelete from " + indexname + " where key = 99 and rid=4444444\0" +     //deleting existing key but secondary column value doesn't match
                    "rdelete from " + indexname + " where key = 100000 and rid=4444444\0" + //deleting non-existing key.
                    "rdelete from " + indexname + " where key = 5 and rid=2\0" +
                    "rinsert into " + indexname + " values(2, 1) where key = 2\0" +
                    "rinsert into " + indexname + " values(2, 19) where key = 2\0" +
                    "rinsert into " + indexname + " values(2, 2) where key = 2\0" +
                    "rdelete from " + indexname + " where key = 2 and rid=19\0";

                try
                {
                    cmd.ExecuteNonQuery();
                    Console.WriteLine("Command executed");
                    conn.Close();
                }
                catch
                {
                }

                Console.WriteLine("Starting protocol service on {0}...", badhost);
                result = Exec.Shell(@"sc \\" + badhost + " start QueryAnalyzer_Protocol", true); // Suppress error.
                Console.WriteLine(result);

                System.Threading.Thread.Sleep(1000 * 3);
            }

            Dictionary <string, string> renamed = new Dictionary <string, string>();
            {
                Console.WriteLine("Invalidating chunks on the bad host...");

                string bulkget = @"\\" + System.Net.Dns.GetHostName() + @"\" + Environment.CurrentDirectory.Replace(':', '$') + @"\" + Guid.NewGuid().ToString().Replace("-", "");
                Exec.Shell("Qizmt bulkget " + bulkget + " RDBMS_Table_" + tablename);
                string[] lines = System.IO.File.ReadAllLines(bulkget);
                System.IO.File.Delete(bulkget);

                foreach (string line in lines)
                {
                    string[] parts     = line.Split(' ');
                    string   firsthost = parts[0].Split(';')[0];
                    string   chunkname = parts[1];
                    string   oldpath   = @"\\" + firsthost + @"\" + qizmtrootdir + @"\" + chunkname;
                    string   newpath   = oldpath + "_regtest";
                    System.IO.File.Move(oldpath, newpath);
                    renamed.Add(oldpath, newpath);
                }
            }

            {
                Console.WriteLine("RSelecting from rindex...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = " + string.Join(",", allhosts) + "; rindex=pooled";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "rselect * from " + indexname + " where key=80 or key = 2 or key = 5 or key=9 or key=10 or key=14 or key=20 or key=21 or key=25 or key=30 or key=90 or key=99 or key=102";
                DbDataReader reader = cmd.ExecuteReader();
                int          cnt    = 0;
                List <KeyValuePair <int, int> > results = new List <KeyValuePair <int, int> >();
                while (reader.Read())
                {
                    int x = reader.GetInt32(0);
                    int y = reader.GetInt32(1);
                    KeyValuePair <int, int> row = new KeyValuePair <int, int>(x, y);
                    results.Add(row);
                }
                reader.Close();
                conn.Close();

                results.Sort(delegate(KeyValuePair <int, int> x, KeyValuePair <int, int> y)
                {
                    if (x.Key != y.Key)
                    {
                        return(x.Key.CompareTo(y.Key));
                    }
                    else
                    {
                        return(x.Value.CompareTo(y.Value));
                    }
                });

                List <KeyValuePair <int, int> > expected = new List <KeyValuePair <int, int> >();
                expected.Add(new KeyValuePair <int, int>(2, 1));
                expected.Add(new KeyValuePair <int, int>(2, 2));
                expected.Add(new KeyValuePair <int, int>(5, 1));
                expected.Add(new KeyValuePair <int, int>(9, 1));
                expected.Add(new KeyValuePair <int, int>(9, 2));
                expected.Add(new KeyValuePair <int, int>(10, 1));
                expected.Add(new KeyValuePair <int, int>(10, 2));
                expected.Add(new KeyValuePair <int, int>(10, 3));
                expected.Add(new KeyValuePair <int, int>(14, 1));
                expected.Add(new KeyValuePair <int, int>(20, 1));
                expected.Add(new KeyValuePair <int, int>(21, 1));
                expected.Add(new KeyValuePair <int, int>(25, 1));
                expected.Add(new KeyValuePair <int, int>(30, 1));
                expected.Add(new KeyValuePair <int, int>(30, 2));
                expected.Add(new KeyValuePair <int, int>(90, 1));
                expected.Add(new KeyValuePair <int, int>(99, 1));
                expected.Add(new KeyValuePair <int, int>(102, 1));

                if (results.Count != expected.Count)
                {
                    throw new Exception("Expected " + expected.Count.ToString() + " rows to be returned.  But received " + results.Count.ToString() + " rows instead.");
                }

                for (int i = 0; i < results.Count; i++)
                {
                    if (results[i].Key != expected[i].Key || results[i].Value != expected[i].Value)
                    {
                        throw new Exception("Row returned is different from expected results.  Received row:(" + results[i].Key.ToString() + "," + results[i].Value.ToString() + ").  Expected row:(" + expected[i].Key.ToString() + "," + expected[i].Value.ToString() + ")");
                    }
                }
            }

            {
                Console.WriteLine("Fixing chunks...");
                foreach (KeyValuePair <string, string> pair in renamed)
                {
                    System.IO.File.Move(pair.Value, pair.Key);
                }
            }

            {
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "drop table " + tablename;
                cmd.ExecuteNonQuery();
                cmd.CommandText = "drop rindex " + indexname;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }
Example #7
0
        public static void RIndexMutable()
        {
            string guid            = Guid.NewGuid().ToString().Replace("-", "");
            string tablename       = "rselect_test_" + guid;
            string indexname       = guid + "apple";
            string indexname_order = guid + "order";

            string[] allhosts = null;
            {
                string[] installs = Exec.Shell("Qizmt slaveinstalls").Trim()
                                    .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                allhosts = new string[installs.Length];

                for (int ip = 0; ip < installs.Length; ip++)
                {
                    string[] parts = installs[ip].Split(' ');
                    allhosts[ip] = parts[0];
                }
            }

            System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("DSpace_DataProvider");

            {
                Console.WriteLine("Creating data, table, and index...");

                string job = (@"<SourceCode>
  <Jobs>
    <Job Name=`Cleanup_Previous_Data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                //Clean up previous data.
               Shell(@`Qizmt del data_Input" + guid + @"*`);
                Shell(@`Qizmt del data_Output" + guid + @"*`);   
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);

                using (DbConnection conn = fact.CreateConnection())
                {
                    try
                    {
                        conn.ConnectionString = `Data Source = localhost`;
                        conn.Open();
                        DbCommand cmd = conn.CreateCommand();
                        cmd.CommandText = `drop table " + tablename + @"`;
                        cmd.ExecuteNonQuery();  
                        cmd.CommandText = `drop rindex " + indexname + @"`;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                    catch
                    {

                    }
                }           
            }
        ]]>
      </Local>
    </Job>
    <Job Name=`data_CreateSampleData` Custodian=`` Email=`` Description=`Create sample data`>
      <IOSettings>
        <JobType>remote</JobType>
        <DFS_IO>
          <DFSReader></DFSReader>
          <DFSWriter>dfs://data_Input" + guid + @".txt</DFSWriter>
        </DFS_IO>
      </IOSettings>
      <Remote>
        <![CDATA[
            public virtual void Remote(RemoteInputStream dfsinput, RemoteOutputStream dfsoutput)
            {
                dfsoutput.WriteLine(`1`);
            }
        ]]>
      </Remote>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"1.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(-10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(5);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(5);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"2.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(10);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(10);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(14);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"3.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(21);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(25);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(80);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(80);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"4.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(80);
                    rkey.PutInt(3);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(80);
                    rkey.PutInt(4);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(90);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(102);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
<Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"5.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(102);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(102);
                    rkey.PutInt(3);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`Prepare_tblFriends_Table_Create_RIndex` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>RDBMS_DBCORE</Using>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                Shell(@`qizmt combine data_Output" + guid + @"1.bin data_Output" + guid + @"2.bin data_Output" + guid + @"3.bin data_Output" + guid + @"4.bin data_Output" + guid + @"5.bin +data_Output" + guid + @".bin`);
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);
                
                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create table " + tablename + @" (id int, rid int)`;
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = `insert into " + tablename + @" bind 'dfs://data_Output" + guid + @".bin'`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }

                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create rindex " + indexname + @" from " + tablename + @" pinmemoryHASH ON id`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }         
        }
        ]]>
      </Local>
    </Job>
  </Jobs>
</SourceCode>").Replace('`', '"');
                string tempdir = @"\\" + System.Net.Dns.GetHostName() + @"\" + Environment.CurrentDirectory.Replace(':', '$') + @"\" + Guid.NewGuid().ToString().Replace("-", "");
                if (System.IO.Directory.Exists(tempdir))
                {
                    System.IO.Directory.Delete(tempdir, true);
                }
                System.IO.Directory.CreateDirectory(tempdir);
                string tempjobname = Guid.NewGuid().ToString();
                System.IO.File.WriteAllText(tempdir + @"\" + tempjobname, job);

                Exec.Shell("Qizmt importdir \"" + tempdir + "\"");

                Exec.Shell("dspace exec " + tempjobname);

                //Clean up
                Exec.Shell(@"Qizmt del " + tempjobname);
                System.IO.Directory.Delete(tempdir, true);
            }

            {
                Console.WriteLine("RInsert/RDeleting rindex...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = " + string.Join(",", allhosts) + "; rindex=pooled";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText =
                    "BEGIN BULKUPDATE rinsert into " + indexname + " values(-22, -23) where key = -22\0" +
                    "rinsert into " + indexname + " values(-24, -23) where key = -24\0" +
                    "rdelete from " + indexname + " where key = -24 and rid=-23\0" +
                    "rdelete from " + indexname + " where key = -15 and rid=-10\0" +
                    "rdelete from " + indexname + " where key = 80 and rid=1\0" +
                    "rdelete from " + indexname + " where key = 80 and rid=2\0" +
                    "rdelete from " + indexname + " where key = 80 and rid=3\0" +
                    "rdelete from " + indexname + " where key = 80 and rid=4\0" +
                    "rinsert into " + indexname + " values(10, 3) where key = 10\0" +
                    "rinsert into " + indexname + " values(10, 19) where key = 10\0" +
                    "rdelete from " + indexname + " where key = 10 and rid=19\0" +
                    "rinsert into " + indexname + " values(20, 1) where key = 20\0" +
                    "rinsert into " + indexname + " values(30, 1) where key = 30\0" +
                    "rinsert into " + indexname + " values(30, 2) where key = 30\0" +
                    "rinsert into " + indexname + " values(9, 1) where key = 9\0" +
                    "rinsert into " + indexname + " values(9, 2) where key = 9\0" +
                    "rinsert into " + indexname + " values(99, 1) where key = 99\0" +
                    "rdelete from " + indexname + " where key = 99 and rid=4444444\0" +     //deleting existing key but secondary column value doesn't match
                    "rdelete from " + indexname + " where key = 100000 and rid=4444444\0" + //deleting non-existing key.
                    "rdelete from " + indexname + " where key = 5 and rid=2\0" +
                    "rinsert into " + indexname + " values(2, 1) where key = 2\0" +
                    "rinsert into " + indexname + " values(2, 19) where key = 2\0" +
                    "rinsert into " + indexname + " values(2, 2) where key = 2\0" +
                    "rdelete from " + indexname + " where key = 2 and rid=19\0" +
                    "rdelete from " + indexname + " where key = 102 and rid=2\0" +
                    "rdelete from " + indexname + " where key = 102 and rid=3 END BULKUPDATE";
                cmd.ExecuteNonQuery();
                conn.Close();
            }

            {
                Console.WriteLine("RSelecting from rindex...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = " + string.Join(",", allhosts) + "; rindex=pooled";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "rselect * from " + indexname + " where key = -24 or key = -15 or key=-22 or key=80 or key = 2 or key = 5 or key=9 or key=10 or key=14 or key=20 or key=21 or key=25 or key=30 or key=90 or key=99 or key=102";
                DbDataReader reader = cmd.ExecuteReader();
                int          cnt    = 0;
                List <KeyValuePair <int, int> > results = new List <KeyValuePair <int, int> >();
                while (reader.Read())
                {
                    int x = reader.GetInt32(0);
                    int y = reader.GetInt32(1);
                    KeyValuePair <int, int> row = new KeyValuePair <int, int>(x, y);
                    results.Add(row);
                }
                reader.Close();
                conn.Close();

                results.Sort(delegate(KeyValuePair <int, int> x, KeyValuePair <int, int> y)
                {
                    if (x.Key != y.Key)
                    {
                        return(x.Key.CompareTo(y.Key));
                    }
                    else
                    {
                        return(x.Value.CompareTo(y.Value));
                    }
                });

                List <KeyValuePair <int, int> > expected = new List <KeyValuePair <int, int> >();
                expected.Add(new KeyValuePair <int, int>(-22, -23));
                expected.Add(new KeyValuePair <int, int>(2, 1));
                expected.Add(new KeyValuePair <int, int>(2, 2));
                expected.Add(new KeyValuePair <int, int>(5, 1));
                expected.Add(new KeyValuePair <int, int>(9, 1));
                expected.Add(new KeyValuePair <int, int>(9, 2));
                expected.Add(new KeyValuePair <int, int>(10, 1));
                expected.Add(new KeyValuePair <int, int>(10, 2));
                expected.Add(new KeyValuePair <int, int>(10, 3));
                expected.Add(new KeyValuePair <int, int>(14, 1));
                expected.Add(new KeyValuePair <int, int>(20, 1));
                expected.Add(new KeyValuePair <int, int>(21, 1));
                expected.Add(new KeyValuePair <int, int>(25, 1));
                expected.Add(new KeyValuePair <int, int>(30, 1));
                expected.Add(new KeyValuePair <int, int>(30, 2));
                expected.Add(new KeyValuePair <int, int>(90, 1));
                expected.Add(new KeyValuePair <int, int>(99, 1));
                expected.Add(new KeyValuePair <int, int>(102, 1));

                if (results.Count != expected.Count)
                {
                    throw new Exception("Expected " + expected.Count.ToString() + " rows to be returned.  But received " + results.Count.ToString() + " rows instead.");
                }

                for (int i = 0; i < results.Count; i++)
                {
                    if (results[i].Key != expected[i].Key || results[i].Value != expected[i].Value)
                    {
                        throw new Exception("Row returned is different from expected results.  Received row:(" + results[i].Key.ToString() + "," + results[i].Value.ToString() + ").  Expected row:(" + expected[i].Key.ToString() + "," + expected[i].Value.ToString() + ")");
                    }
                }
            }

            {
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "drop table " + tablename;
                cmd.ExecuteNonQuery();
                cmd.CommandText = "drop rindex " + indexname;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }
        public static void RIndexMutable_SpecialCase_3()
        {
            string guid            = Guid.NewGuid().ToString().Replace("-", "");
            string tablename       = "rselect_test_" + guid;
            string indexname       = guid + "apple";
            string indexname_order = guid + "order";

            string[] allhosts = null;
            {
                string[] installs = Exec.Shell("Qizmt slaveinstalls").Trim()
                                    .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                allhosts = new string[installs.Length];

                for (int ip = 0; ip < installs.Length; ip++)
                {
                    string[] parts = installs[ip].Split(' ');
                    allhosts[ip] = parts[0];
                }
            }

            System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("DSpace_DataProvider");

            {
                Console.WriteLine("Creating data, table, and index...");

                string job = (@"<SourceCode>
  <Jobs>
    <Job Name=`Cleanup_Previous_Data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                //Clean up previous data.
               Shell(@`Qizmt del data_Input" + guid + @"*`);
                Shell(@`Qizmt del data_Output" + guid + @"*`);   
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);

                using (DbConnection conn = fact.CreateConnection())
                {
                    try
                    {
                        conn.ConnectionString = `Data Source = localhost`;
                        conn.Open();
                        DbCommand cmd = conn.CreateCommand();
                        cmd.CommandText = `drop table " + tablename + @"`;
                        cmd.ExecuteNonQuery();  
                        cmd.CommandText = `drop rindex " + indexname + @"`;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                    catch
                    {

                    }
                }           
            }
        ]]>
      </Local>
    </Job>
    <Job Name=`data_CreateSampleData` Custodian=`` Email=`` Description=`Create sample data`>
      <IOSettings>
        <JobType>remote</JobType>
        <DFS_IO>
          <DFSReader></DFSReader>
          <DFSWriter>dfs://data_Input" + guid + @".txt</DFSWriter>
        </DFS_IO>
      </IOSettings>
      <Remote>
        <![CDATA[
            public virtual void Remote(RemoteInputStream dfsinput, RemoteOutputStream dfsoutput)
            {
                dfsoutput.WriteLine(`1`);
            }
        ]]>
      </Remote>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"1.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(1);                    
                    output.Add(rkey.ToByteSlice());      
                } 
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(2);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(3);                    
                    output.Add(rkey.ToByteSlice());      
                }  
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(4);                    
                    output.Add(rkey.ToByteSlice());      
                } 
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(5);                    
                    output.Add(rkey.ToByteSlice());      
                }     
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(6);                    
                    output.Add(rkey.ToByteSlice());      
                }           
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"2.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(7);                    
                    output.Add(rkey.ToByteSlice());      
                }  
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(8);                    
                    output.Add(rkey.ToByteSlice());      
                }     
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"3.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(9);                    
                    output.Add(rkey.ToByteSlice());      
                }      
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(10);                    
                    output.Add(rkey.ToByteSlice());      
                } 
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"4.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(11);                    
                    output.Add(rkey.ToByteSlice());      
                }  
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(12);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(-15);
                    rkey.PutInt(13);                    
                    output.Add(rkey.ToByteSlice());      
                }    
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`Prepare_tblFriends_Table_Create_RIndex` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>RDBMS_DBCORE</Using>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                Shell(@`qizmt combine data_Output" + guid + @"1.bin data_Output" + guid + @"2.bin data_Output" + guid + @"3.bin data_Output" + guid + @"4.bin +data_Output" + guid + @".bin`);
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);
                
                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create table " + tablename + @" (id int, rid int)`;
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = `insert into " + tablename + @" bind 'dfs://data_Output" + guid + @".bin'`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }

                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create rindex " + indexname + @" from " + tablename + @" pinmemoryHASH ON id`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }         
        }
        ]]>
      </Local>
    </Job>
  </Jobs>
</SourceCode>").Replace('`', '"');
                string tempdir = @"\\" + System.Net.Dns.GetHostName() + @"\" + Environment.CurrentDirectory.Replace(':', '$') + @"\" + Guid.NewGuid().ToString().Replace("-", "");
                if (System.IO.Directory.Exists(tempdir))
                {
                    System.IO.Directory.Delete(tempdir, true);
                }
                System.IO.Directory.CreateDirectory(tempdir);
                string tempjobname = Guid.NewGuid().ToString();
                System.IO.File.WriteAllText(tempdir + @"\" + tempjobname, job);

                Exec.Shell("Qizmt importdir \"" + tempdir + "\"");

                Exec.Shell("dspace exec " + tempjobname);

                //Clean up
                Exec.Shell(@"Qizmt del " + tempjobname);
                System.IO.Directory.Delete(tempdir, true);
            }

            {
                Console.WriteLine("RInsert/RDeleting rindex...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = " + string.Join(",", allhosts) + "; rindex=pooled";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "rdelete from " + indexname + " where key=-15";
                cmd.ExecuteNonQuery();
                conn.Close();
            }

            {
                Console.WriteLine("RSelecting from rindex...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = " + string.Join(",", allhosts) + "; rindex=pooled";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "rselect * from " + indexname + " where key=-15";
                DbDataReader reader = cmd.ExecuteReader();
                int          cnt    = 0;
                List <KeyValuePair <int, int> > results = new List <KeyValuePair <int, int> >();
                bool found = false;
                while (reader.Read())
                {
                    throw new Exception("Not supposed to return any results.");
                }
                reader.Close();
                conn.Close();
            }

            {
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "drop table " + tablename;
                cmd.ExecuteNonQuery();
                cmd.CommandText = "drop rindex " + indexname;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }
Example #9
0
        public static void RSelectSpillageTest2()
        {
            string guid            = Guid.NewGuid().ToString().Replace("-", "");
            string tablename       = "rselect_test_" + guid;
            string indexname       = guid + "apple";
            string indexname_order = guid + "order";

            System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("DSpace_DataProvider");

            {
                Console.WriteLine("Creating data, table, and index...");

                string job = (@"<SourceCode>
  <Jobs>
    <Job Name=`Cleanup_Previous_Data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                //Clean up previous data.
               Shell(@`Qizmt del data_Input" + guid + @"*`);
                Shell(@`Qizmt del data_Output" + guid + @"*`);   
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);

                using (DbConnection conn = fact.CreateConnection())
                {
                    try
                    {
                        conn.ConnectionString = `Data Source = localhost`;
                        conn.Open();
                        DbCommand cmd = conn.CreateCommand();
                        cmd.CommandText = `drop table " + tablename + @"`;
                        cmd.ExecuteNonQuery();  
                        cmd.CommandText = `drop rindex " + indexname + @"`;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                    catch
                    {

                    }
                }           
            }
        ]]>
      </Local>
    </Job>
    <Job Name=`data_CreateSampleData` Custodian=`` Email=`` Description=`Create sample data`>
      <IOSettings>
        <JobType>remote</JobType>
        <DFS_IO>
          <DFSReader></DFSReader>
          <DFSWriter>dfs://data_Input" + guid + @".txt</DFSWriter>
        </DFS_IO>
      </IOSettings>
      <Remote>
        <![CDATA[
            public virtual void Remote(RemoteInputStream dfsinput, RemoteOutputStream dfsoutput)
            {
                dfsoutput.WriteLine(`1`);
            }
        ]]>
      </Remote>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"1.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                for(int i = 0; i < 2; i++)
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(1);
                    rkey.PutInt(0);
                    
                    output.Add(rkey.ToByteSlice());       
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"2.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());   
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                for(int i = 0; i < 2; i++)
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutInt(0);
                    
                    output.Add(rkey.ToByteSlice());       
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"3.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);
                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());   
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {              
                for(int i = 0; i < 2; i++)
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutInt(i);
                    
                    output.Add(rkey.ToByteSlice());       
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
<Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"4.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);
                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());   
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {              
                for(int i = 0; i < 2; i++)
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutInt(i);
                    
                    output.Add(rkey.ToByteSlice());       
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
<Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"5.bin@nInt,nInt</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);
                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());   
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {              
                for(int i = 0; i < 2; i++)
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(4);
                    rkey.PutInt(i);
                    
                    output.Add(rkey.ToByteSlice());       
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`Prepare_tblFriends_Table_Create_RIndex` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>RDBMS_DBCORE</Using>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                Shell(@`qizmt combine data_Output" + guid + @"1.bin data_Output" + guid + @"2.bin data_Output" + guid + @"3.bin data_Output" + guid + @"4.bin data_Output" + guid + @"5.bin +data_Output" + guid + @".bin`);
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);
                
                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create table " + tablename + @" (id int, rid int)`;
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = `insert into " + tablename + @" bind 'dfs://data_Output" + guid + @".bin'`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }

                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create rindex " + indexname + @" from " + tablename + @" pinmemoryHASH ON id`;
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = `create rindex " + indexname_order + @" from " + tablename + @" pinmemoryHASH keepvalueorder ON id`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }         
        }
        ]]>
      </Local>
    </Job>
  </Jobs>
</SourceCode>").Replace('`', '"');
                string tempdir = @"\\" + System.Net.Dns.GetHostName() + @"\" + Environment.CurrentDirectory.Replace(':', '$') + @"\" + Guid.NewGuid().ToString().Replace("-", "");
                if (System.IO.Directory.Exists(tempdir))
                {
                    System.IO.Directory.Delete(tempdir, true);
                }
                System.IO.Directory.CreateDirectory(tempdir);
                string tempjobname = Guid.NewGuid().ToString();
                System.IO.File.WriteAllText(tempdir + @"\" + tempjobname, job);

                Exec.Shell("Qizmt importdir \"" + tempdir + "\"");

                Exec.Shell("dspace exec " + tempjobname);

                //Clean up
                Exec.Shell(@"Qizmt del " + tempjobname);
                System.IO.Directory.Delete(tempdir, true);
            }

            {
                Console.WriteLine("RSelecting from rindex...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost; rindex=pooled";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "rselect * from " + indexname + " where key = 2";
                DbDataReader reader = cmd.ExecuteReader();
                int          cnt    = 0;
                while (reader.Read())
                {
                    if (reader.GetInt32(0) != 2)
                    {
                        throw new Exception("Expected value.");
                    }
                    cnt++;
                }
                reader.Close();
                if (cnt != 6)
                {
                    throw new Exception("Expected 6 rows, but received only " + cnt.ToString());
                }
                conn.Close();
            }

            {
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "drop table " + tablename;
                cmd.ExecuteNonQuery();
                cmd.CommandText = "drop rindex " + indexname;
                cmd.ExecuteNonQuery();
                cmd.CommandText = "drop rindex " + indexname_order;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }
Example #10
0
        public static void FaultTolerantExecution()
        {
            if (!MySpace.DataMining.AELight.FTTest.enabled)
            {
                throw new Exception("TESTFAULTTOLERANT is not #defined.  Need Qizmt build with all #define TESTFAULTTOLERANT uncommented.");
            }

            string guid           = "A275169D14B34df48229FC3F43A0AA31";
            string tblUsers       = "users_" + guid;
            string tblPageviews   = "pageviews_" + guid;
            string tblPageToNames = "pagetonames_" + guid;
            string controlfile    = @"\\" + MySpace.DataMining.AELight.Surrogate.MasterHost + @"\c$\temp\"
                                    + MySpace.DataMining.AELight.FTTest.controlfilename;

            string tempdir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) +
                             @"\" + Guid.NewGuid().ToString();

            System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("Qizmt_DataProvider");
            DbConnection conn = fact.CreateConnection();

            conn.ConnectionString = "Data Source = localhost; mr bypass=10; fault tolerant execution=enabled";
            DbCommand cmd = conn.CreateCommand();

            try
            {
                {
                    System.IO.Directory.CreateDirectory(tempdir);

                    #region genPageViews
                    System.IO.File.WriteAllText(tempdir + @"\genPageViews_873200A2-EFD4-4136-9209-A807CF8BA3C2.xml",
                                                @"<SourceCode>
  <Jobs>
    <Job Name=`Preprocessing` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                Shell(@`Qizmt del tblPageViews_873200A2-EFD4-4136-9209-A807CF8BA3C2_Output.bin`);
            }
        ]]>
      </Local>
    </Job>
    <Job Name=`CreateSampleData` Custodian=`` Email=`` Description=`Create sample data`>
      <IOSettings>
        <JobType>remote</JobType>
        <DFS_IO>
          <DFSReader></DFSReader>
          <DFSWriter>dfs://tblPageViews_873200A2-EFD4-4136-9209-A807CF8BA3C2_Output.bin@8</DFSWriter>
        </DFS_IO>
      </IOSettings>
      <Remote>
        <![CDATA[
            public virtual void Remote(RemoteInputStream dfsinput, RemoteOutputStream dfsoutput)
            {
                List<byte> buf = new List<byte>(24);
                
                {
                    recordset rs  = recordset.Prepare();
                    rs.PutInt(100);
                    rs.PutInt(1);
                    rs.ToByteSlice().AppendTo(buf);
                    dfsoutput.WriteRecord(buf);
                }
                {
                    buf.Clear();
                    recordset rs  = recordset.Prepare();
                    rs.PutInt(101);
                    rs.PutInt(1);
                    rs.ToByteSlice().AppendTo(buf);
                    dfsoutput.WriteRecord(buf);
                }
                {
                    buf.Clear();
                    recordset rs  = recordset.Prepare();
                    rs.PutInt(300);
                    rs.PutInt(3);
                    rs.ToByteSlice().AppendTo(buf);
                    dfsoutput.WriteRecord(buf);
                }
                {
                    buf.Clear();
                    recordset rs  = recordset.Prepare();
                    rs.PutInt(301);
                    rs.PutInt(3);
                    rs.ToByteSlice().AppendTo(buf);
                    dfsoutput.WriteRecord(buf);
                }
                {
                    buf.Clear();
                    recordset rs  = recordset.Prepare();
                    rs.PutInt(302);
                    rs.PutInt(3);
                    rs.ToByteSlice().AppendTo(buf);
                    dfsoutput.WriteRecord(buf);
                }
                {
                    buf.Clear();
                    recordset rs  = recordset.Prepare();
                    rs.PutInt(400);
                    rs.PutInt(4);
                    rs.ToByteSlice().AppendTo(buf);
                    dfsoutput.WriteRecord(buf);
                }
            }
        ]]>
      </Remote>
    </Job>
  </Jobs>
</SourceCode>
".Replace('`', '"'));
                    #endregion

                    #region genPageToNames
                    System.IO.File.WriteAllText(tempdir + @"\genPageToNames_873200A2-EFD4-4136-9209-A807CF8BA3C2.xml",
                                                @"<SourceCode>
  <Jobs>
    <Job Name=`Preprocessing` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                Shell(@`Qizmt del tblPageToNames_873200A2-EFD4-4136-9209-A807CF8BA3C2_Output.txt`);
            }
        ]]>
      </Local>
    </Job>
    <Job Name=`CreateSampleData` Custodian=`` Email=`` Description=`Create sample data`>
      <IOSettings>
        <JobType>remote</JobType>
        <DFS_IO>
          <DFSReader></DFSReader>
          <DFSWriter>dfs://tblPageToNames_873200A2-EFD4-4136-9209-A807CF8BA3C2_Output.txt</DFSWriter>
        </DFS_IO>
      </IOSettings>
      <Remote>
        <![CDATA[
            public virtual void Remote(RemoteInputStream dfsinput, RemoteOutputStream dfsoutput)
            {
                //Create sample data.
                dfsoutput.WriteLine(`90,a`);
                dfsoutput.WriteLine(`91,b`);
                dfsoutput.WriteLine(`92,c`);
                dfsoutput.WriteLine(`93,d`);
                dfsoutput.WriteLine(`94,e`);
            }
        ]]>
      </Remote>
    </Job>
  </Jobs>
</SourceCode>
".Replace('`', '"'));
                    #endregion

                    Exec.Shell("qizmt importdir \"" + tempdir + "\"");
                    Exec.Shell("qizmt exec genPageViews_873200A2-EFD4-4136-9209-A807CF8BA3C2.xml");
                    Exec.Shell("qizmt exec genPageToNames_873200A2-EFD4-4136-9209-A807CF8BA3C2.xml");
                }

                conn.Open();

                #region createtables
                {
                    Console.WriteLine("Creating tables...");

                    try
                    {
                        cmd.CommandText = "drop table " + tblUsers;
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "drop table " + tblPageviews;
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "drop table " + tblPageToNames;
                        cmd.ExecuteNonQuery();
                        conn.Close(); //flush
                    }
                    catch
                    {
                    }

                    conn.Open();
                    cmd.CommandText = "create table " + tblUsers + " (userid int, username char(50))";
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "insert into " + tblUsers + " values (1, 'john')";
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "insert into " + tblUsers + " values (2, 'mary')";
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "insert into " + tblUsers + " values (3, 'joe')";
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = "create table " + tblPageviews + " (pageid int, uid int)";
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = "create table " + tblPageToNames + " (pageid int, username char(50))";
                    cmd.ExecuteNonQuery();

                    conn.Close(); //flush
                    conn.Open();
                }
                #endregion

                #region testIMPORT
                {
                    string phase = "exchangeowned";
                    Console.WriteLine("Testing IMPORT in FTE mode with failure at {0}...", phase);
                    using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                    {
                        w.WriteLine("{1}:" + phase);
                    }

                    cmd.CommandText = "INSERT INTO " + tblPageviews + " IMPORT 'tblPageViews_873200A2-EFD4-4136-9209-A807CF8BA3C2_Output.bin'";
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    conn.Open();

                    System.IO.File.WriteAllText(controlfile, "");
                    cmd.CommandText = "select * from " + tblPageviews;
                    DbDataReader reader = cmd.ExecuteReader();
                    int          count  = 0;
                    while (reader.Read())
                    {
                        count++;
                        int pageid = reader.GetInt32(0);
                        int userid = reader.GetInt32(1);
                        if (!(pageid == 100 && userid == 1) && !(pageid == 101 && userid == 1) &&
                            !(pageid == 300 && userid == 3) && !(pageid == 301 && userid == 3) && !(pageid == 302 && userid == 3) &&
                            !(pageid == 400 && userid == 4))
                        {
                            throw new Exception("Unexpected value");
                        }
                    }
                    reader.Close();
                    if (count != 6)
                    {
                        throw new Exception("Unexpected rows returned");
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testIMPORTLINES
                {
                    string phase = "reduce";
                    Console.WriteLine("Testing IMPORTLINES in FTE mode with failure at {0}...", phase);
                    using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                    {
                        w.WriteLine("{1}:" + phase);
                    }

                    cmd.CommandText = "INSERT INTO " + tblPageToNames + " IMPORTLINES 'tblPageToNames_873200A2-EFD4-4136-9209-A807CF8BA3C2_Output.txt'";
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    conn.Open();

                    System.IO.File.WriteAllText(controlfile, "");
                    cmd.CommandText = "select * from " + tblPageToNames;
                    DbDataReader reader = cmd.ExecuteReader();
                    int          count  = 0;
                    while (reader.Read())
                    {
                        count++;
                        int    pageid = reader.GetInt32(0);
                        string name   = reader.GetString(1);
                        if (!(pageid == 90 && name == "a") && !(pageid == 91 && name == "b") &&
                            !(pageid == 92 && name == "c") && !(pageid == 93 && name == "d") &&
                            !(pageid == 94 && name == "e"))
                        {
                            throw new Exception("Unexpected value");
                        }
                    }
                    reader.Close();
                    if (count != 5)
                    {
                        throw new Exception("Unexpected rows returned");
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testSELECT
                {
                    string phase = "map";
                    Console.WriteLine("Testing SELECT in FTE mode with failure at {0}...", phase);
                    using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                    {
                        w.WriteLine("{1}:" + phase);
                    }

                    cmd.CommandText = "select * from " + tblUsers + " where userid = 2";
                    DbDataReader reader = cmd.ExecuteReader();
                    int          count  = 0;
                    while (reader.Read())
                    {
                        count++;
                        if (reader.GetString(1) != "mary")
                        {
                            throw new Exception("Unexpected value for field username");
                        }
                    }
                    reader.Close();
                    if (count != 1)
                    {
                        throw new Exception("Unexpected rows returned");
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testSELECT
                {
                    string phase = "exchangeremote";
                    Console.WriteLine("Testing SELECT in FTE mode with failure at {0}...", phase);
                    using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                    {
                        w.WriteLine("{1}:" + phase);
                    }

                    cmd.CommandText = "select * from " + tblUsers + " where userid > 0";
                    DbDataReader reader = cmd.ExecuteReader();
                    int          count  = 0;
                    while (reader.Read())
                    {
                        count++;
                        string username = reader.GetString(1);
                        if (username != "mary" && username != "john" && username != "joe")
                        {
                            throw new Exception("Unexpected value for field username");
                        }
                    }
                    reader.Close();
                    if (count != 3)
                    {
                        throw new Exception("Unexpected rows returned");
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testSELECT
                {
                    string phase = "exchangeowned";
                    Console.WriteLine("Testing SELECT in FTE mode with failure at {0}...", phase);
                    using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                    {
                        w.WriteLine("{1}:" + phase);
                    }

                    cmd.CommandText = "select username from " + tblUsers + " where userid=3";
                    DbDataReader reader = cmd.ExecuteReader();
                    int          count  = 0;
                    while (reader.Read())
                    {
                        count++;
                        if (reader.GetString(0) != "joe")
                        {
                            throw new Exception("Unexpected value for field username");
                        }
                    }
                    reader.Close();
                    if (count != 1)
                    {
                        throw new Exception("Unexpected rows returned");
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testSELECT
                {
                    string phase = "sort";
                    Console.WriteLine("Testing SELECT in FTE mode with failure at {0}...", phase);
                    using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                    {
                        w.WriteLine("{1}:" + phase);
                    }

                    cmd.CommandText = "select username from " + tblUsers + " where abs(userid)=3";
                    DbDataReader reader = cmd.ExecuteReader();
                    int          count  = 0;
                    while (reader.Read())
                    {
                        count++;
                        if (reader.GetString(0) != "joe")
                        {
                            throw new Exception("Unexpected value for field username");
                        }
                    }
                    reader.Close();
                    if (count != 1)
                    {
                        throw new Exception("Unexpected rows returned");
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testSELECT
                {
                    Console.WriteLine("Testing SELECT in FTE mode with no failure...");
                    System.IO.File.WriteAllText(controlfile, ""); //Do not simulate failure since FTE is not enabled for SELECT func(column)

                    cmd.CommandText = "select max(pageid), uid from " + tblPageviews + " group by uid";
                    DbDataReader reader = cmd.ExecuteReader();
                    int          count  = 0;
                    while (reader.Read())
                    {
                        count++;
                        int pageid = reader.GetInt32(0);
                        int uid    = reader.GetInt32(1);
                        if (!(pageid == 101 && uid == 1) && !(pageid == 302 && uid == 3) && !(pageid == 400 && uid == 4))
                        {
                            throw new Exception("Unexpected value");
                        }
                    }
                    reader.Close();
                    if (count != 3)
                    {
                        throw new Exception("Unexpected rows returned");
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testINNERJOIN
                {
                    string phase = "reduce";
                    Console.WriteLine("Testing INNER JOIN in FTE mode with failure at {0}...", phase);
                    using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                    {
                        w.WriteLine("{1}:" + phase);
                    }

                    cmd.CommandText = "SELECT * FROM " + tblPageviews + " inner join " + tblUsers + " on uid=userid";
                    DbDataReader reader = cmd.ExecuteReader();
                    int          count  = 0;
                    while (reader.Read())
                    {
                        count++;
                        int    pageid   = reader.GetInt32(0);
                        string username = reader.GetString(3);
                        if (!(pageid == 100 && username == "john") && !(pageid == 101 && username == "john") &&
                            !(pageid == 300 && username == "joe") && !(pageid == 301 && username == "joe") &&
                            !(pageid == 302 && username == "joe"))
                        {
                            throw new Exception("Unexpected value");
                        }
                    }
                    reader.Close();
                    if (count != 5)
                    {
                        throw new Exception("Unexpected rows returned");
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testINNERJOIN
                {
                    string phase = "sort";
                    Console.WriteLine("Testing INNER JOIN in FTE mode with failure at {0}...", phase);
                    using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                    {
                        w.WriteLine("{1}:" + phase);
                    }

                    long jid = GetJobID("RDBMS_JoinOn.DBCORE");
                    if (jid != -1)
                    {
                        throw new Exception("Expected jobid = -1");
                    }

                    List <string> errors = new List <string>();

                    System.Threading.Thread tm = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
                    {
                        while (jid == -1)
                        {
                            Console.Write(".");
                            System.Threading.Thread.Sleep(1000);
                            jid = GetJobID("RDBMS_JoinOn.DBCORE");
                        }
                        Console.WriteLine("jid={0}", jid);

                        for (; ;)
                        {
                            Console.Write(".");
                            System.Threading.Thread.Sleep(1000);
                            if (GetJobOutputIndexOf(jid, "Replicating") > -1)
                            {
                                //Can clear control file for the next job run.
                                ClearControlFile(controlfile);
                                Console.WriteLine("control file cleared");
                                break;
                            }
                        }
                    }));

                    tm.IsBackground = true;
                    tm.Start();

                    System.Threading.Thread ts = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
                    {
                        cmd.CommandText = "select max(pageid), username from " + tblPageviews +
                                          " inner join " + tblUsers + " on uid = userid group by username";
                        DbDataReader reader = cmd.ExecuteReader();
                        int count           = 0;
                        while (reader.Read())
                        {
                            count++;
                            int pageid      = reader.GetInt32(0);
                            string username = reader.GetString(1);
                            if (!(pageid == 101 && username == "john") && !(pageid == 302 && username == "joe"))
                            {
                                errors.Add("Unexpected value");
                                throw new Exception("Unexpected value");
                            }
                        }
                        reader.Close();
                        if (count != 2)
                        {
                            errors.Add("Unexpected rows returned");
                            throw new Exception("Unexpected rows returned");
                        }
                    }));

                    ts.IsBackground = true;
                    ts.Start();

                    tm.Join();
                    ts.Join();

                    if (errors.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (string err in errors)
                        {
                            sb.Append(err);
                            sb.Append(Environment.NewLine);
                        }
                        throw new Exception("Error during job run:" + sb.ToString());
                    }

                    Console.WriteLine("Done");
                }
                #endregion

                #region testLEFTJOIN
                {
                    string phase = "replication";
                    Console.WriteLine("Testing LEFT OUTER JOIN in FTE mode with failure at {0}...", phase);
                    using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                    {
                        w.WriteLine("{1}:" + phase);
                    }

                    cmd.CommandText = "SELECT * FROM " + tblPageviews + " left outer join " + tblUsers + " on uid=userid";
                    DbDataReader reader = cmd.ExecuteReader();
                    int          count  = 0;
                    while (reader.Read())
                    {
                        count++;
                        int    pageid   = (int)reader[0];
                        string username = DBNull.Value.Equals(reader[3]) ? null : (string)reader[3];
                        if (!(pageid == 100 && username == "john") && !(pageid == 101 && username == "john") &&
                            !(pageid == 300 && username == "joe") && !(pageid == 301 && username == "joe") &&
                            !(pageid == 302 && username == "joe") && !(pageid == 400 && username == null))
                        {
                            throw new Exception("Unexpected value");
                        }
                    }
                    reader.Close();
                    if (count != 6)
                    {
                        throw new Exception("Unexpected rows returned");
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testRIGHTJOIN
                {
                    string phase = "map";
                    Console.WriteLine("Testing RIGHT OUTER JOIN in FTE mode with failure at {0}...", phase);
                    using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                    {
                        w.WriteLine("{1}:" + phase);
                    }

                    cmd.CommandText = "SELECT * FROM " + tblPageviews + " right outer join " + tblUsers + " on uid=userid";
                    DbDataReader reader = cmd.ExecuteReader();
                    int          count  = 0;
                    while (reader.Read())
                    {
                        count++;
                        int userid = (int)reader[2];
                        int pageid = DBNull.Value.Equals(reader[0]) ? -1 : (int)reader[0];
                        if (!(userid == 1 && pageid == 100) && !(userid == 1 && pageid == 101) &&
                            !(userid == 3 && pageid == 300) && !(userid == 3 && pageid == 301) &&
                            !(userid == 3 && pageid == 302) && !(userid == 2 && pageid == -1))
                        {
                            throw new Exception("Unexpected value");
                        }
                    }
                    reader.Close();
                    if (count != 6)
                    {
                        throw new Exception("Unexpected rows returned");
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testDELETE
                {
                    {
                        string phase = "exchangeremote";
                        Console.WriteLine("Testing DELETE in FTE mode with failure at {0}...", phase);
                        using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                        {
                            w.WriteLine("{1}:" + phase);
                        }

                        cmd.CommandText = "DELETE FROM " + tblPageToNames + " where username='******'";
                        cmd.ExecuteNonQuery();
                        conn.Close(); //flush
                        conn.Open();
                        Console.WriteLine("+");
                    }
                    {
                        string phase = "exchangeowned";
                        Console.WriteLine("Testing DELETE in FTE mode with failure at {0}...", phase);
                        using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                        {
                            w.WriteLine("{1}:" + phase);
                        }

                        cmd.CommandText = "DELETE FROM " + tblPageToNames + " where abs(pageid)= 93";
                        cmd.ExecuteNonQuery();
                        conn.Close(); //flush
                        conn.Open();
                        Console.WriteLine("+");
                    }
                    {
                        string phase = "sort";
                        Console.WriteLine("Testing DELETE in FTE mode with failure at {0}...", phase);
                        using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                        {
                            w.WriteLine("{1}:" + phase);
                        }

                        cmd.CommandText = "delete from " + tblPageToNames + " where mod(pageid, 2) = 0";
                        cmd.ExecuteNonQuery();
                        conn.Close(); //flush
                        conn.Open();
                        Console.WriteLine("+");
                    }
                    {
                        System.IO.File.WriteAllText(controlfile, "");
                        cmd.CommandText = "select * from " + tblPageToNames;
                        DbDataReader reader = cmd.ExecuteReader();
                        int          count  = 0;
                        while (reader.Read())
                        {
                            count++;
                        }
                        reader.Close();
                        if (count != 0)
                        {
                            throw new Exception("Unexpected number of rows returned");
                        }
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testINSERT
                {
                    {
                        string phase = "reduce";
                        Console.WriteLine("Testing INSERT in FTE mode with failure at {0}...", phase);
                        using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                        {
                            w.WriteLine("{1}:" + phase);
                        }

                        cmd.CommandText = "insert into " + tblPageToNames +
                                          " select userid, username from " + tblUsers + " where userid > 2";
                        cmd.ExecuteNonQuery();
                        conn.Close(); //flush
                        conn.Open();
                        Console.WriteLine("+");
                    }
                    {
                        Console.WriteLine("Testing INSERT in FTE mode with no failure");
                        System.IO.File.WriteAllText(controlfile, "");

                        cmd.CommandText = "insert into " + tblPageToNames +
                                          " select abs(userid), username from " + tblUsers + " where userid = 2";
                        cmd.ExecuteNonQuery();
                        conn.Close(); //flush
                        conn.Open();
                        Console.WriteLine("+");
                    }
                    {
                        Console.WriteLine("Testing INSERT in FTE mode with no failure");

                        cmd.CommandText = "insert into " + tblPageToNames +
                                          " select userid, username from " + tblUsers +
                                          " where userid = 1 order by userid";
                        cmd.ExecuteNonQuery();
                        conn.Close(); //flush
                        conn.Open();
                        Console.WriteLine("+");
                    }
                    {
                        System.IO.File.WriteAllText(controlfile, "");
                        cmd.CommandText = "select * from " + tblPageToNames;
                        DbDataReader reader = cmd.ExecuteReader();
                        int          count  = 0;
                        while (reader.Read())
                        {
                            count++;
                            int    pageid   = reader.GetInt32(0);
                            string username = reader.GetString(1);
                            if (!(pageid == 1 && username == "john") && !(pageid == 2 && username == "mary") &&
                                !(pageid == 3 && username == "joe"))
                            {
                                throw new Exception("Unexpected value");
                            }
                        }
                        reader.Close();
                        if (count != 3)
                        {
                            throw new Exception("Unexpected number of rows returned");
                        }
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region testINSERT
                {
                    //prepare
                    {
                        System.IO.File.WriteAllText(controlfile, "");
                        cmd.CommandText = "delete from " + tblPageToNames + " where pageid > 0";
                        cmd.ExecuteNonQuery();
                        conn.Close(); //flush
                        conn.Open();
                    }

                    {
                        string phase = "exchangeowned";
                        Console.WriteLine("Testing INSERT in FTE mode with failure at {0}...", phase);
                        using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                        {
                            w.WriteLine("{1}:" + phase);
                        }

                        long jid = GetJobID("RDBMS_JoinOn.DBCORE");
                        if (jid != -1)
                        {
                            throw new Exception("Expected jobid = -1");
                        }

                        System.Threading.Thread tm = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
                        {
                            while (jid == -1)
                            {
                                Console.Write(".");
                                System.Threading.Thread.Sleep(1000);
                                jid = GetJobID("RDBMS_JoinOn.DBCORE");
                            }
                            Console.WriteLine("jid={0}", jid);

                            for (; ;)
                            {
                                Console.Write(".");
                                System.Threading.Thread.Sleep(1000);
                                if (GetJobOutputIndexOf(jid, "Replicating") > -1)
                                {
                                    //Can clear control file for the next job run.
                                    ClearControlFile(controlfile);
                                    Console.WriteLine("control file cleared");
                                    break;
                                }
                            }
                        }));

                        tm.IsBackground = true;
                        tm.Start();

                        System.Threading.Thread ts = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
                        {
                            cmd.CommandText = "insert into " + tblPageToNames +
                                              " select abs(pageid), username from " + tblPageviews +
                                              " inner join " + tblUsers + " on uid = userid where abs(userid) = 1";
                            cmd.ExecuteNonQuery();
                            conn.Close(); //flush
                            conn.Open();
                        }));

                        ts.IsBackground = true;
                        ts.Start();

                        tm.Join();
                        ts.Join();
                        Console.WriteLine("+");
                    }
                    {
                        string phase = "exchangeremote";
                        Console.WriteLine("Testing INSERT in FTE mode with failure at {0}...", phase);
                        using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                        {
                            w.WriteLine("{1}:" + phase);
                        }

                        long jid = GetJobID("RDBMS_JoinOn.DBCORE");
                        if (jid != -1)
                        {
                            throw new Exception("Expected jobid = -1");
                        }

                        System.Threading.Thread tm = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
                        {
                            while (jid == -1)
                            {
                                Console.Write(".");
                                System.Threading.Thread.Sleep(1000);
                                jid = GetJobID("RDBMS_JoinOn.DBCORE");
                            }
                            Console.WriteLine("jid={0}", jid);

                            for (; ;)
                            {
                                Console.Write(".");
                                System.Threading.Thread.Sleep(1000);
                                if (GetJobOutputIndexOf(jid, "Replicating") > -1)
                                {
                                    //Can clear control file for the next job run.
                                    ClearControlFile(controlfile);
                                    Console.WriteLine("control file cleared");
                                    break;
                                }
                            }
                        }));

                        tm.IsBackground = true;
                        tm.Start();

                        System.Threading.Thread ts = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
                        {
                            cmd.CommandText = "insert into " + tblPageToNames +
                                              " select abs(pageid), username from " + tblPageviews +
                                              " inner join " + tblUsers +
                                              " on uid = userid where abs(userid) = 3 order by pageid";
                            cmd.ExecuteNonQuery();
                            conn.Close(); //flush
                            conn.Open();
                        }));

                        ts.IsBackground = true;
                        ts.Start();

                        tm.Join();
                        ts.Join();
                        Console.WriteLine("+");
                    }
                    {
                        string phase = "sort";
                        Console.WriteLine("Testing INSERT in FTE mode with failure at {0}...", phase);
                        using (System.IO.StreamWriter w = new System.IO.StreamWriter(controlfile))
                        {
                            w.WriteLine("{1}:" + phase);
                        }

                        long jid = GetJobID("RDBMS_JoinOn.DBCORE");
                        if (jid != -1)
                        {
                            throw new Exception("Expected jobid = -1");
                        }

                        System.Threading.Thread tm = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
                        {
                            while (jid == -1)
                            {
                                Console.Write(".");
                                System.Threading.Thread.Sleep(1000);
                                jid = GetJobID("RDBMS_JoinOn.DBCORE");
                            }
                            Console.WriteLine("jid={0}", jid);

                            for (; ;)
                            {
                                Console.Write(".");
                                System.Threading.Thread.Sleep(1000);
                                if (GetJobOutputIndexOf(jid, "Replicating") > -1)
                                {
                                    //Can clear control file for the next job run.
                                    ClearControlFile(controlfile);
                                    Console.WriteLine("control file cleared");
                                    break;
                                }
                            }
                        }));

                        tm.IsBackground = true;
                        tm.Start();

                        System.Threading.Thread ts = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
                        {
                            cmd.CommandText = "insert into " + tblPageToNames +
                                              " select max(userid), username from " + tblPageviews +
                                              " inner join " + tblUsers +
                                              " on uid = userid group by username";
                            cmd.ExecuteNonQuery();
                            conn.Close(); //flush
                            conn.Open();
                        }));

                        ts.IsBackground = true;
                        ts.Start();

                        tm.Join();
                        ts.Join();
                        Console.WriteLine("+");
                    }

                    {
                        System.IO.File.WriteAllText(controlfile, "");
                        cmd.CommandText = "select * from " + tblPageToNames;
                        DbDataReader reader = cmd.ExecuteReader();
                        int          count  = 0;
                        while (reader.Read())
                        {
                            count++;
                            int    pageid   = reader.GetInt32(0);
                            string username = reader.GetString(1);
                            if (!(pageid == 100 && username == "john") && !(pageid == 101 && username == "john") &&
                                !(pageid == 300 && username == "joe") && !(pageid == 301 && username == "joe") &&
                                !(pageid == 302 && username == "joe") && !(pageid == 1 && username == "john") &&
                                !(pageid == 3 && username == "joe"))
                            {
                                throw new Exception("Unexpected value");
                            }
                        }
                        reader.Close();

                        if (count != 7)
                        {
                            throw new Exception("Unexpected number of rows returned");
                        }
                    }
                    Console.WriteLine("Done");
                }
                #endregion

                #region cleanup
                try
                {
                    cmd.CommandText = "drop table " + tblUsers;
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "drop table " + tblPageviews;
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "drop table " + tblPageToNames;
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                }
                #endregion
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    try
                    {
                        conn.Close();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Closing error: " + e.ToString());
                    }
                }

                System.IO.Directory.Delete(tempdir, true);
                Exec.Shell("qizmt del *873200A2-EFD4-4136-9209-A807CF8BA3C2*");
                System.IO.File.Delete(controlfile);
            }
        }
Example #11
0
        static int GetJobOutputIndexOf(long jobid, string token)
        {
            string output = Exec.Shell("qizmt viewjob " + jobid.ToString());

            return(output.IndexOf(token, StringComparison.OrdinalIgnoreCase));
        }
Example #12
0
        public static void RIndexSampling()
        {
            string guid            = Guid.NewGuid().ToString().Replace("-", "");
            string tablename       = "rselect_test_" + guid;
            string indexname       = guid + "apple";
            string indexname_order = guid + "order";

            string[] allhosts = null;
            {
                string[] installs = Exec.Shell("Qizmt slaveinstalls").Trim()
                                    .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                allhosts = new string[installs.Length];

                for (int ip = 0; ip < installs.Length; ip++)
                {
                    string[] parts = installs[ip].Split(' ');
                    allhosts[ip] = parts[0];
                }
            }

            System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("DSpace_DataProvider");

            {
                Console.WriteLine("Creating data, table, and index...");

                string job = (@"<SourceCode>
  <Jobs>
    <Job Name=`Cleanup_Previous_Data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                //Clean up previous data.
               Shell(@`Qizmt del data_Input" + guid + @"*`);
                Shell(@`Qizmt del data_Output" + guid + @"*`);   
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);

                using (DbConnection conn = fact.CreateConnection())
                {
                    try
                    {
                        conn.ConnectionString = `Data Source = localhost`;
                        conn.Open();
                        DbCommand cmd = conn.CreateCommand();
                        cmd.CommandText = `drop table " + tablename + @"`;
                        cmd.ExecuteNonQuery();  
                        cmd.CommandText = `drop rindex " + indexname + @"`;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                    catch
                    {

                    }
                }           
            }
        ]]>
      </Local>
    </Job>
    <Job Name=`data_CreateSampleData` Custodian=`` Email=`` Description=`Create sample data`>
      <IOSettings>
        <JobType>remote</JobType>
        <DFS_IO>
          <DFSReader></DFSReader>
          <DFSWriter>dfs://data_Input" + guid + @".txt</DFSWriter>
        </DFS_IO>
      </IOSettings>
      <Remote>
        <![CDATA[
            public virtual void Remote(RemoteInputStream dfsinput, RemoteOutputStream dfsoutput)
            {
                dfsoutput.WriteLine(`1`);
            }
        ]]>
      </Remote>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"1.bin@nInt,nChar(10)</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(1);
                    rkey.PutString(`101`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(1);
                    rkey.PutString(`102`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
               {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(1);
                    rkey.PutString(`103`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(1);
                    rkey.PutString(`104`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(1);
                    rkey.PutString(`105`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(1);
                    rkey.PutString(`106`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(1);
                    rkey.PutString(`107`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(1);
                    rkey.PutString(`108`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(1);
                    rkey.PutString(`109`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`201`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`202`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"2.bin@nInt,nChar(10)</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                 {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`203`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`204`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`205`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`206`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`207`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`208`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`209`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`210`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"3.bin@nInt,nChar(10)</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`211`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(2);
                    rkey.PutString(`212`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(3);
                    rkey.PutString(`301`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(3);
                    rkey.PutString(`302`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(3);
                    rkey.PutString(`303`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(3);
                    rkey.PutString(`304`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`data` Custodian=`` Email=``>
      <IOSettings>
        <JobType>mapreduce</JobType>
        <KeyLength>nInt</KeyLength>
        <DFSInput>dfs://data_Input" + guid + @".txt</DFSInput>
        <DFSOutput>dfs://data_Output" + guid + @"4.bin@nInt,nChar(10)</DFSOutput>
        <OutputMethod>grouped</OutputMethod>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Using>RDBMS_DBCORE</Using>
      <MapReduce>
        <Map>
          <![CDATA[
            public virtual void Map(ByteSlice line, MapOutput output)
            {                
                DbRecordset rkey = DbRecordset.Prepare();
                rkey.PutInt(4);                
                output.Add(rkey.ToByteSlice(), ByteSlice.Prepare());
            }
        ]]>
        </Map>
        <Reduce>
          <![CDATA[
            public override void Reduce(ByteSlice key, ByteSliceList values, ReduceOutput output)
            {
                 {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(3);
                    rkey.PutString(`305`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(4);
                    rkey.PutString(`401`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
                {
                    DbRecordset rkey = DbRecordset.Prepare();
                    rkey.PutInt(4);
                    rkey.PutString(`402`, 10);                    
                    output.Add(rkey.ToByteSlice());      
                }
            }
        ]]>
        </Reduce>
      </MapReduce>
    </Job>
    <Job Name=`Prepare_tblFriends_Table_Create_RIndex` Custodian=`` Email=``>
      <IOSettings>
        <JobType>local</JobType>
      </IOSettings>
      <Add Reference=`RDBMS_DBCORE.dll` Type=`dfs`/>
      <Add Reference=`System.Data.dll` Type=`system`/>
      <Using>RDBMS_DBCORE</Using>
      <Using>System.Data</Using>
      <Using>System.Data.Common</Using>
      <Local>
        <![CDATA[
            public virtual void Local()
            {
                Shell(@`qizmt combine data_Output" + guid + @"1.bin data_Output" + guid + @"2.bin data_Output" + guid + @"3.bin data_Output" + guid + @"4.bin +data_Output" + guid + @".bin`);
                
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory(`Qizmt_DataProvider`);
                
                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create table " + tablename + @" (id int, rid char(10))`;
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = `insert into " + tablename + @" bind 'dfs://data_Output" + guid + @".bin'`;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }

                using (DbConnection conn = fact.CreateConnection())
                {
                    conn.ConnectionString = `Data Source = localhost`;
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = `create rindex " + indexname + @" from " + tablename + @" pinmemoryHASH ON id `;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }         
        }
        ]]>
      </Local>
    </Job>
  </Jobs>
</SourceCode>").Replace('`', '"');
                string tempdir = @"\\" + System.Net.Dns.GetHostName() + @"\" + Environment.CurrentDirectory.Replace(':', '$') + @"\" + Guid.NewGuid().ToString().Replace("-", "");
                if (System.IO.Directory.Exists(tempdir))
                {
                    System.IO.Directory.Delete(tempdir, true);
                }
                System.IO.Directory.CreateDirectory(tempdir);
                string tempjobname = Guid.NewGuid().ToString();
                System.IO.File.WriteAllText(tempdir + @"\" + tempjobname, job);

                Exec.Shell("Qizmt importdir \"" + tempdir + "\"");

                Exec.Shell("dspace exec " + tempjobname);

                //Clean up
                Exec.Shell(@"Qizmt del " + tempjobname);
                System.IO.Directory.Delete(tempdir, true);
            }

            {
                Console.WriteLine("RSelecting samples from rindex...");
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = " + string.Join(",", allhosts) + "; rindex=pooled";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                //Getting something not in the table also.
                cmd.CommandText = "rselect * from " + indexname + " sample 5 where key=-888 or key = 1 or key = 2 or key=3 or key=4 or key=-9999";
                DbDataReader reader = cmd.ExecuteReader();
                Dictionary <int, List <string> > results = new Dictionary <int, List <string> >();
                while (reader.Read())
                {
                    int    x = reader.GetInt32(0);
                    string y = reader.GetString(1);
                    if (!results.ContainsKey(x))
                    {
                        results.Add(x, new List <string>());
                    }
                    results[x].Add(y);
                }
                reader.Close();
                conn.Close();

                Dictionary <int, Dictionary <string, int> > expected = new Dictionary <int, Dictionary <string, int> >();
                expected.Add(1, new Dictionary <string, int>());
                for (int i = 101; i <= 109; i++)
                {
                    expected[1].Add(i.ToString(), 0);
                }
                expected.Add(2, new Dictionary <string, int>());
                for (int i = 201; i <= 212; i++)
                {
                    expected[2].Add(i.ToString(), 0);
                }
                expected.Add(3, new Dictionary <string, int>());
                for (int i = 301; i <= 305; i++)
                {
                    expected[3].Add(i.ToString(), 0);
                }
                expected.Add(4, new Dictionary <string, int>());
                for (int i = 401; i <= 402; i++)
                {
                    expected[4].Add(i.ToString(), 0);
                }

                //Make sure the correct number of samples are returned.
                Dictionary <int, int> expectedCount = new Dictionary <int, int>();
                expectedCount.Add(1, 5);
                expectedCount.Add(2, 5);
                expectedCount.Add(3, 5);
                expectedCount.Add(4, 2);

                foreach (int key in results.Keys)
                {
                    if (!expected.ContainsKey(key))
                    {
                        throw new Exception("Unexpected key received: " + key.ToString());
                    }

                    foreach (string val in results[key])
                    {
                        if (!expected[key].ContainsKey(val))
                        {
                            throw new Exception("The pair: (" + key.ToString() + ", '" + val + "') is not found.");
                        }

                        if (expected[key][val] != 0)
                        {
                            throw new Exception("The pair: (" + key.ToString() + ", '" + val + "') is returned more than once.");
                        }

                        expected[key][val]++;
                    }

                    if (results[key].Count != expectedCount[key])
                    {
                        throw new Exception("Expected rows to be returned for key= " + key.ToString() + " is " + expectedCount[key].ToString() + ", but got " + results[key].Count.ToString() + " rows instead.");
                    }
                }
            }

            {
                DbConnection conn = fact.CreateConnection();
                conn.ConnectionString = "Data Source = localhost";
                conn.Open();
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "drop table " + tablename;
                cmd.ExecuteNonQuery();
                cmd.CommandText = "drop rindex " + indexname;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }