public void Revisions() { if (!HasHQL) { return; } Ns.Exec("CREATE TABLE fruit (tag, description)"); Ns.Exec("INSERT INTO fruit VALUES" + "(\"2009-08-02 08:30:00\", \"banana\", \"tag:great\", \"Had with lunch\")"); var cells = Ns.Query("SELECT * FROM fruit"); Assert.IsNotNull(cells); Assert.AreEqual(1, cells.Count); Assert.AreEqual(cells[0].Key.Row, "banana"); Assert.AreEqual(cells[0].Key.ColumnFamily, "tag"); Assert.AreEqual(cells[0].Key.ColumnQualifier, "great"); Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with lunch"); Assert.AreEqual(cells[0].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 0, DateTimeKind.Local).ToUniversalTime()); Ns.Exec("INSERT INTO fruit VALUES" + "(\"2009-08-02 08:30:01\", \"banana\", \"tag:great\", \"Had with dinner\")"); cells = Ns.Query("SELECT * FROM fruit"); Assert.IsNotNull(cells); Assert.AreEqual(2, cells.Count); Assert.AreEqual(cells[0].Key.Row, "banana"); Assert.AreEqual(cells[0].Key.ColumnFamily, "tag"); Assert.AreEqual(cells[0].Key.ColumnQualifier, "great"); Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with dinner"); Assert.AreEqual(cells[0].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 1, DateTimeKind.Local).ToUniversalTime()); Assert.AreEqual(cells[1].Key.Row, "banana"); Assert.AreEqual(cells[1].Key.ColumnFamily, "tag"); Assert.AreEqual(cells[1].Key.ColumnQualifier, "great"); Assert.AreEqual(Encoding.Default.GetString(cells[1].Value), "Had with lunch"); Assert.AreEqual(cells[1].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 0, DateTimeKind.Local).ToUniversalTime()); Ns.Exec("INSERT INTO fruit VALUES" + "(\"2009-08-02 08:30:01\", \"banana\", \"tag:great\", \"Had with breakfast\")"); cells = Ns.Query("SELECT * FROM fruit"); Assert.IsNotNull(cells); Assert.AreEqual(2, cells.Count); Assert.AreEqual(cells[0].Key.Row, "banana"); Assert.AreEqual(cells[0].Key.ColumnFamily, "tag"); Assert.AreEqual(cells[0].Key.ColumnQualifier, "great"); Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with breakfast"); Assert.AreEqual(cells[0].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 1, DateTimeKind.Local).ToUniversalTime()); Assert.AreEqual(cells[1].Key.Row, "banana"); Assert.AreEqual(cells[1].Key.ColumnFamily, "tag"); Assert.AreEqual(cells[1].Key.ColumnQualifier, "great"); Assert.AreEqual(Encoding.Default.GetString(cells[1].Value), "Had with lunch"); Assert.AreEqual(cells[1].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 0, DateTimeKind.Local).ToUniversalTime()); Ns.Exec("DROP TABLE fruit"); }
public void Unsupported() { if (HasHQL) { return; } try { Ns.Exec("CREATE NAMESPACE abc"); Assert.Fail(); } catch (NotImplementedException) { } }
public void Query() { if (!HasHQL) { return; } Ns.Exec("CREATE TABLE fruit (tag, description)"); Ns.Exec( "INSERT INTO fruit VALUES" + "(\"cantelope\", \"tag:good\", \"Had with breakfast\")," + "(\"2009-08-02 08:30:00\", \"cantelope\", \"description\", \"A cultivated variety of muskmelon with orange flesh\")," + "(\"banana\", \"tag:great\", \"Had with lunch\")"); ValidateFruitTable("fruit"); Ns.Exec("DELETE description FROM fruit WHERE ROW=\"cantelope\""); var cells = Ns.Query("SELECT * FROM fruit", "SELECT * FROM fruit WHERE ROW=\"banana\""); // multiple queries Assert.IsNotNull(cells); Assert.AreEqual(3, cells.Count); Assert.AreEqual(cells[0].Key.Row, "banana"); Assert.AreEqual(cells[0].Key.ColumnFamily, "tag"); Assert.AreEqual(cells[0].Key.ColumnQualifier, "great"); Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with lunch"); Assert.AreEqual(cells[1].Key.Row, "cantelope"); Assert.AreEqual(cells[1].Key.ColumnFamily, "tag"); Assert.AreEqual(cells[1].Key.ColumnQualifier, "good"); Assert.AreEqual(Encoding.Default.GetString(cells[1].Value), "Had with breakfast"); Assert.AreEqual(cells[2].Key.Row, "banana"); Assert.AreEqual(cells[2].Key.ColumnFamily, "tag"); Assert.AreEqual(cells[2].Key.ColumnQualifier, "great"); Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with lunch"); Ns.Exec("DROP TABLE fruit"); }
public void Exec() { if (!HasHQL) { return; } try { Ns.Exec("this is not hql"); Assert.Fail(); } catch (HqlParseException) { } catch { Assert.Fail(); } try { Ns.Exec("DROP TABLE table_does_not_exists"); Assert.Fail(); } catch (TableNotFoundException) { } catch { Assert.Fail(); } Ns.Exec("DROP TABLE IF EXISTS table_does_not_exists"); try { Ns.Exec("DROP NAMESPACE namespace_does_not_exists"); Assert.Fail(); } catch (NamespaceDoesNotExistsException) { } catch { Assert.Fail(); } Ns.Exec("DROP NAMESPACE IF EXISTS namespace_does_not_exists"); Ns.Exec("CREATE NAMESPACE abc"); try { Ns.Exec("USE abc"); Assert.Fail(); } catch (BadNamespaceException) { } catch { Assert.Fail(); } Ns.Exec("DROP NAMESPACE abc"); Ns.Exec("CREATE TABLE t (a, description)"); Ns.Exec("ALTER TABLE t ADD (e) RENAME COLUMN FAMILY (a, tag)"); Ns.Exec("RENAME TABLE t TO fruit"); Ns.Exec( "INSERT INTO fruit VALUES" + "(\"cantelope\", \"tag:good\", \"Had with breakfast\")," + "(\"2009-08-02 08:30:00\", \"cantelope\", \"description\", \"A cultivated variety of muskmelon with orange flesh\")," + "(\"banana\", \"tag:great\", \"Had with lunch\")"); Ns.Exec("DELETE * FROM fruit WHERE ROW=\"banana\"", "DROP TABLE fruit"); // multiple commands }
public void DumpAndLoadData() { if (!HasHQL) { return; } var tempPath = Path.GetTempPath(); var filenames = new[] { tempPath + "DumpTest.txt", tempPath + "DumpTest.gz", "fs://DumpTest.txt", "fs://DumpTest.gz" }; { Ns.Exec("DROP TABLE IF EXISTS fruit", "CREATE TABLE fruit (tag, description)"); Ns.Exec( "INSERT INTO fruit VALUES" + "(\"cantelope\", \"tag:good\", \"Had with breakfast\")," + "(\"2009-08-02 08:30:00\", \"cantelope\", \"description\", \"A cultivated variety of muskmelon with orange flesh\")," + "(\"banana\", \"tag:great\", \"Had with lunch\")"); ValidateFruitTable("fruit"); foreach (var filename in filenames) { Ns.Exec(string.Format("DUMP TABLE fruit INTO FILE '{0}'", filename)); var fname = filename; if (filename.StartsWith("fs:")) { fname = Path.Combine( (string)Context.Properties["Hypertable.DataDirectory"], "fs/local", filename.Replace("fs://", "")); } Assert.IsTrue(File.Exists(fname)); Ns.Exec("DROP TABLE IF EXISTS fruit2", "CREATE TABLE fruit2 (tag, description)"); Ns.Exec(string.Format("LOAD DATA INFILE '{0}' INTO TABLE fruit2", filename)); ValidateFruitTable("fruit2"); File.Delete(fname); } foreach (var filename in filenames) { Ns.Exec(string.Format("SELECT * FROM fruit DISPLAY_TIMESTAMPS INTO FILE '{0}'", filename)); var fname = filename; if (filename.StartsWith("fs:")) { fname = Path.Combine( (string)Context.Properties["Hypertable.DataDirectory"], "fs/local", filename.Replace("fs://", "")); } Assert.IsTrue(File.Exists(fname)); Ns.Exec("DROP TABLE IF EXISTS fruit2", "CREATE TABLE fruit2 (tag, description)"); Ns.Exec(string.Format("LOAD DATA INFILE '{0}' INTO TABLE fruit2", filename)); ValidateFruitTable("fruit2"); File.Delete(fname); } Ns.Exec("DROP TABLE fruit", "DROP TABLE fruit2"); } { const string Schema = "<Schema><AccessGroup><ColumnFamily><Name>bin</Name></ColumnFamily></AccessGroup></Schema>"; var rng = new Random(); var buf = new byte[1024]; var all = new byte[255]; for (var i = 0; i < 255; ++i) { all[i] = (byte)i; } var data = new Dictionary <string, byte[]>(); var table = Ns.OpenTable("bin", Schema, OpenDispositions.CreateAlways); using (var mutator = table.CreateMutator()) { var key = new Key { ColumnFamily = "bin" }; for (var i = 0; i < 10000; ++i) { do { key.Row = Guid.NewGuid().ToString(); }while (data.ContainsKey(key.Row)); rng.NextBytes(buf); mutator.Set(key, buf); data.Add(key.Row, (byte[])buf.Clone()); } do { key.Row = Guid.NewGuid().ToString(); }while (data.ContainsKey(key.Row)); mutator.Set(key, all); data.Add(key.Row, (byte[])all.Clone()); } foreach (var filename in filenames) { Ns.Exec(string.Format("DUMP TABLE bin INTO FILE '{0}'", filename)); var fname = filename; if (filename.StartsWith("fs:")) { fname = Path.Combine( (string)Context.Properties["Hypertable.DataDirectory"], "fs/local", filename.Replace("fs://", "")); } Assert.IsTrue(File.Exists(fname)); Ns.Exec("DROP TABLE IF EXISTS bin2", "CREATE TABLE bin2 (bin)"); Ns.Exec(string.Format("LOAD DATA INFILE '{0}' INTO TABLE bin2", filename)); foreach (var cell in table.CreateScanner()) { Assert.IsTrue(data.ContainsKey(cell.Key.Row)); Assert.IsTrue(data[cell.Key.Row].SequenceEqual(cell.Value)); } File.Delete(fname); } Ns.Exec("DROP TABLE bin", "DROP TABLE bin2"); } }