20
20
namespace Apache . Ignite . Core . Tests . Cache . Query
21
21
{
22
22
using System ;
23
- using System . Collections ;
24
23
using System . Collections . Generic ;
25
24
using System . Diagnostics . CodeAnalysis ;
26
25
using System . Linq ;
@@ -156,7 +155,7 @@ public void TestValidationSql()
156
155
public void TestValidationSqlFields ( )
157
156
{
158
157
// 1. No sql.
159
- Assert . Throws < ArgumentException > ( ( ) => { Cache ( ) . QueryFields ( new SqlFieldsQuery ( null ) ) ; } ) ;
158
+ Assert . Throws < ArgumentException > ( ( ) => { Cache ( ) . Query ( new SqlFieldsQuery ( null ) ) ; } ) ;
160
159
}
161
160
162
161
/// <summary>
@@ -285,11 +284,9 @@ public void TestSqlFieldsQueryArguments()
285
284
Cache ( ) . Put ( 3 , new QueryPerson ( "Sidorov" , 50 ) ) ;
286
285
287
286
// 1. Empty result set.
288
- using (
289
- IQueryCursor < IList > cursor = Cache ( ) . QueryFields (
290
- new SqlFieldsQuery ( "SELECT age FROM QueryPerson WHERE age < ?" , 50 ) ) )
287
+ using ( var cursor = Cache ( ) . Query ( new SqlFieldsQuery ( "SELECT age FROM QueryPerson WHERE age < ?" , 50 ) ) )
291
288
{
292
- foreach ( IList entry in cursor . GetAll ( ) )
289
+ foreach ( var entry in cursor . GetAll ( ) )
293
290
Assert . IsTrue ( ( int ) entry [ 0 ] < 50 ) ;
294
291
}
295
292
}
@@ -390,7 +387,7 @@ public void TestSqlFieldsQuery([Values(true, false)] bool loc, [Values(true, fal
390
387
Lazy = lazy
391
388
} ;
392
389
393
- using ( IQueryCursor < IList > cursor = cache . QueryFields ( qry ) )
390
+ using ( var cursor = cache . Query ( qry ) )
394
391
{
395
392
HashSet < int > exp0 = new HashSet < int > ( exp ) ;
396
393
@@ -403,9 +400,12 @@ public void TestSqlFieldsQuery([Values(true, false)] bool loc, [Values(true, fal
403
400
}
404
401
405
402
Assert . AreEqual ( 0 , exp0 . Count ) ;
403
+ Assert . AreEqual ( new [ ] { "NAME" , "AGE" } , cursor . FieldNames ) ;
406
404
}
407
405
408
- using ( IQueryCursor < IList > cursor = cache . QueryFields ( qry ) )
406
+ // Test old API as well.
407
+ #pragma warning disable 618
408
+ using ( var cursor = cache . QueryFields ( qry ) )
409
409
{
410
410
HashSet < int > exp0 = new HashSet < int > ( exp ) ;
411
411
@@ -418,6 +418,7 @@ public void TestSqlFieldsQuery([Values(true, false)] bool loc, [Values(true, fal
418
418
419
419
Assert . AreEqual ( 0 , exp0 . Count ) ;
420
420
}
421
+ #pragma warning restore 618
421
422
}
422
423
423
424
/// <summary>
@@ -622,15 +623,15 @@ public void TestCustomSchema()
622
623
strings [ 1 ] = "foo" ;
623
624
624
625
// Default schema.
625
- var res = doubles . QueryFields ( new SqlFieldsQuery (
626
+ var res = doubles . Query ( new SqlFieldsQuery (
626
627
"select S._val from double as D join \" strings\" .string as S on S._key = D._key" ) )
627
628
. Select ( x => ( string ) x [ 0 ] )
628
629
. Single ( ) ;
629
630
630
631
Assert . AreEqual ( "foo" , res ) ;
631
632
632
633
// Custom schema.
633
- res = doubles . QueryFields ( new SqlFieldsQuery (
634
+ res = doubles . Query ( new SqlFieldsQuery (
634
635
"select S._val from \" doubles\" .double as D join string as S on S._key = D._key" )
635
636
{
636
637
Schema = strings . Name
@@ -667,13 +668,13 @@ public void TestDistributedJoins()
667
668
var sql = "select T0.Age from QueryPerson as T0 " +
668
669
"inner join QueryPerson as T1 on ((? - T1.Age - 1) = T0._key)" ;
669
670
670
- var res = cache . QueryFields ( new SqlFieldsQuery ( sql , count ) ) . GetAll ( ) . Distinct ( ) . Count ( ) ;
671
+ var res = cache . Query ( new SqlFieldsQuery ( sql , count ) ) . GetAll ( ) . Distinct ( ) . Count ( ) ;
671
672
672
673
Assert . Greater ( res , 0 ) ;
673
674
Assert . Less ( res , count ) ;
674
675
675
676
// Test distributed join: returns complete results
676
- res = cache . QueryFields ( new SqlFieldsQuery ( sql , count ) { EnableDistributedJoins = true } )
677
+ res = cache . Query ( new SqlFieldsQuery ( sql , count ) { EnableDistributedJoins = true } )
677
678
. GetAll ( ) . Distinct ( ) . Count ( ) ;
678
679
679
680
Assert . AreEqual ( count , res ) ;
@@ -709,7 +710,7 @@ public void TestCustomKeyValueFieldNames()
709
710
710
711
cache [ 1 ] = new QueryPerson ( "Joe" , 48 ) ;
711
712
712
- var row = cache . QueryFields ( new SqlFieldsQuery ( "select * from QueryPerson" ) ) . GetAll ( ) [ 0 ] ;
713
+ var row = cache . Query ( new SqlFieldsQuery ( "select * from QueryPerson" ) ) . GetAll ( ) [ 0 ] ;
713
714
Assert . AreEqual ( 2 , row . Count ) ;
714
715
Assert . AreEqual ( 48 , row [ 0 ] ) ;
715
716
Assert . AreEqual ( "Joe" , row [ 1 ] ) ;
@@ -736,7 +737,7 @@ public void TestCustomKeyValueFieldNames()
736
737
737
738
cache [ 1 ] = new QueryPerson ( "John" , 33 ) ;
738
739
739
- row = cache . QueryFields ( new SqlFieldsQuery ( "select * from QueryPerson" ) ) . GetAll ( ) [ 0 ] ;
740
+ row = cache . Query ( new SqlFieldsQuery ( "select * from QueryPerson" ) ) . GetAll ( ) [ 0 ] ;
740
741
741
742
Assert . AreEqual ( 3 , row . Count ) ;
742
743
Assert . AreEqual ( 33 , row [ 0 ] ) ;
@@ -746,7 +747,7 @@ public void TestCustomKeyValueFieldNames()
746
747
Assert . AreEqual ( "John" , person . Name ) ;
747
748
748
749
// Check explicit select.
749
- row = cache . QueryFields ( new SqlFieldsQuery ( "select FullKey from QueryPerson" ) ) . GetAll ( ) [ 0 ] ;
750
+ row = cache . Query ( new SqlFieldsQuery ( "select FullKey from QueryPerson" ) ) . GetAll ( ) [ 0 ] ;
750
751
Assert . AreEqual ( 1 , row [ 0 ] ) ;
751
752
}
752
753
@@ -786,10 +787,46 @@ public void TestSqlFieldsQueryTimeout()
786
787
} ;
787
788
788
789
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
789
- var ex = Assert . Throws < CacheException > ( ( ) => cache . QueryFields ( fieldsQry ) . ToArray ( ) ) ;
790
+ var ex = Assert . Throws < CacheException > ( ( ) => cache . Query ( fieldsQry ) . ToArray ( ) ) ;
790
791
Assert . IsTrue ( ex . ToString ( ) . Contains ( "QueryCancelledException: The query was cancelled while executing." ) ) ;
791
792
}
792
793
794
+ /// <summary>
795
+ /// Tests the FieldNames property.
796
+ /// </summary>
797
+ [ Test ]
798
+ public void TestFieldNames ( )
799
+ {
800
+ var cache = Cache ( ) ;
801
+ PopulateCache ( cache , false , 5 , x => true ) ;
802
+
803
+ // Get before iteration.
804
+ var qry = new SqlFieldsQuery ( "SELECT * FROM QueryPerson" ) ;
805
+ var cur = cache . Query ( qry ) ;
806
+ var names = cur . FieldNames ;
807
+
808
+ Assert . AreEqual ( new [ ] { "AGE" , "NAME" } , names ) ;
809
+
810
+ cur . Dispose ( ) ;
811
+ Assert . AreSame ( names , cur . FieldNames ) ;
812
+
813
+ Assert . Throws < NotSupportedException > ( ( ) => cur . FieldNames . Add ( "x" ) ) ;
814
+
815
+ // Custom order, key-val, get after iteration.
816
+ qry . Sql = "SELECT NAME, _key, AGE, _val FROM QueryPerson" ;
817
+ cur = cache . Query ( qry ) ;
818
+ cur . GetAll ( ) ;
819
+
820
+ Assert . AreEqual ( new [ ] { "NAME" , "_KEY" , "AGE" , "_VAL" } , cur . FieldNames ) ;
821
+
822
+ // Get after disposal.
823
+ qry . Sql = "SELECT 1, AGE FROM QueryPerson" ;
824
+ cur = cache . Query ( qry ) ;
825
+ cur . Dispose ( ) ;
826
+
827
+ Assert . AreEqual ( new [ ] { "1" , "AGE" } , cur . FieldNames ) ;
828
+ }
829
+
793
830
/// <summary>
794
831
/// Validates the query results.
795
832
/// </summary>
0 commit comments