-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from mfenniak/compound_indexes
Implemented Compound Indexes
- Loading branch information
Showing
12 changed files
with
512 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Net; | ||
|
||
namespace RethinkDb | ||
{ | ||
public class CompoundIndexBase<TRecord> | ||
{ | ||
private readonly ITableQuery<TRecord> table; | ||
private readonly string name; | ||
private readonly Expression[] indexExpressions; | ||
|
||
protected CompoundIndexBase(ITableQuery<TRecord> table, string name, Expression[] indexExpressions) | ||
{ | ||
this.table = table; | ||
this.name = name; | ||
this.indexExpressions = indexExpressions; | ||
} | ||
|
||
public Expression[] IndexAccessor | ||
{ | ||
get { return indexExpressions; } | ||
} | ||
|
||
public ITableQuery<TRecord> Table | ||
{ | ||
get { return table; } | ||
} | ||
|
||
public string Name | ||
{ | ||
get { return name; } | ||
} | ||
} | ||
|
||
public class CompoundIndex<TRecord, TKey1, TKey2> : CompoundIndexBase<TRecord>, ICompoundIndex<TRecord, TKey1, TKey2> | ||
{ | ||
public CompoundIndex(ITableQuery<TRecord> table, string name, Expression<Func<TRecord, TKey1>> indexExpression1, Expression<Func<TRecord, TKey2>> indexExpression2) | ||
: base(table, name, new Expression[] { indexExpression1, indexExpression2 }) | ||
{ | ||
} | ||
|
||
public CompoundIndexKey<TKey1, TKey2> Key(TKey1 key1, TKey2 key2) | ||
{ | ||
return new CompoundIndexKey<TKey1, TKey2>(key1, key2); | ||
} | ||
} | ||
|
||
public class CompoundIndex<TRecord, TKey1, TKey2, TKey3> : CompoundIndexBase<TRecord>, ICompoundIndex<TRecord, TKey1, TKey2, TKey3> | ||
{ | ||
public CompoundIndex(ITableQuery<TRecord> table, string name, Expression<Func<TRecord, TKey1>> indexExpression1, Expression<Func<TRecord, TKey2>> indexExpression2, Expression<Func<TRecord, TKey3>> indexExpression3) | ||
: base(table, name, new Expression[] { indexExpression1, indexExpression2, indexExpression3 }) | ||
{ | ||
} | ||
|
||
public CompoundIndexKey<TKey1, TKey2, TKey3> Key(TKey1 key1, TKey2 key2, TKey3 key3) | ||
{ | ||
return new CompoundIndexKey<TKey1, TKey2, TKey3>(key1, key2, key3); | ||
} | ||
} | ||
|
||
public class CompoundIndex<TRecord, TKey1, TKey2, TKey3, TKey4> : CompoundIndexBase<TRecord>, ICompoundIndex<TRecord, TKey1, TKey2, TKey3, TKey4> | ||
{ | ||
public CompoundIndex(ITableQuery<TRecord> table, string name, Expression<Func<TRecord, TKey1>> indexExpression1, Expression<Func<TRecord, TKey2>> indexExpression2, Expression<Func<TRecord, TKey3>> indexExpression3, Expression<Func<TRecord, TKey4>> indexExpression4) | ||
: base(table, name, new Expression[] { indexExpression1, indexExpression2, indexExpression3, indexExpression4 }) | ||
{ | ||
} | ||
|
||
public CompoundIndexKey<TKey1, TKey2, TKey3, TKey4> Key(TKey1 key1, TKey2 key2, TKey3 key3, TKey4 key4) | ||
{ | ||
return new CompoundIndexKey<TKey1, TKey2, TKey3, TKey4>(key1, key2, key3, key4); | ||
} | ||
} | ||
|
||
public class CompoundIndex<TRecord, TKey1, TKey2, TKey3, TKey4, TKey5> : CompoundIndexBase<TRecord>, ICompoundIndex<TRecord, TKey1, TKey2, TKey3, TKey4, TKey5> | ||
{ | ||
public CompoundIndex(ITableQuery<TRecord> table, string name, Expression<Func<TRecord, TKey1>> indexExpression1, Expression<Func<TRecord, TKey2>> indexExpression2, Expression<Func<TRecord, TKey3>> indexExpression3, Expression<Func<TRecord, TKey4>> indexExpression4, Expression<Func<TRecord, TKey5>> indexExpression5) | ||
: base(table, name, new Expression[] { indexExpression1, indexExpression2, indexExpression3, indexExpression4, indexExpression5 }) | ||
{ | ||
} | ||
|
||
public CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5> Key(TKey1 key1, TKey2 key2, TKey3 key3, TKey4 key4, TKey5 key5) | ||
{ | ||
return new CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5>(key1, key2, key3, key4, key5); | ||
} | ||
} | ||
|
||
public class CompoundIndex<TRecord, TKey1, TKey2, TKey3, TKey4, TKey5, TKey6> : CompoundIndexBase<TRecord>, ICompoundIndex<TRecord, TKey1, TKey2, TKey3, TKey4, TKey5, TKey6> | ||
{ | ||
public CompoundIndex(ITableQuery<TRecord> table, string name, Expression<Func<TRecord, TKey1>> indexExpression1, Expression<Func<TRecord, TKey2>> indexExpression2, Expression<Func<TRecord, TKey3>> indexExpression3, Expression<Func<TRecord, TKey4>> indexExpression4, Expression<Func<TRecord, TKey5>> indexExpression5, Expression<Func<TRecord, TKey6>> indexExpression6) | ||
: base(table, name, new Expression[] { indexExpression1, indexExpression2, indexExpression3, indexExpression4, indexExpression5, indexExpression6 }) | ||
{ | ||
} | ||
|
||
public CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5, TKey6> Key(TKey1 key1, TKey2 key2, TKey3 key3, TKey4 key4, TKey5 key5, TKey6 key6) | ||
{ | ||
return new CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5, TKey6>(key1, key2, key3, key4, key5, key6); | ||
} | ||
} | ||
|
||
public class CompoundIndex<TRecord, TKey1, TKey2, TKey3, TKey4, TKey5, TKey6, TKey7> : CompoundIndexBase<TRecord>, ICompoundIndex<TRecord, TKey1, TKey2, TKey3, TKey4, TKey5, TKey6, TKey7> | ||
{ | ||
public CompoundIndex(ITableQuery<TRecord> table, string name, Expression<Func<TRecord, TKey1>> indexExpression1, Expression<Func<TRecord, TKey2>> indexExpression2, Expression<Func<TRecord, TKey3>> indexExpression3, Expression<Func<TRecord, TKey4>> indexExpression4, Expression<Func<TRecord, TKey5>> indexExpression5, Expression<Func<TRecord, TKey6>> indexExpression6, Expression<Func<TRecord, TKey7>> indexExpression7) | ||
: base(table, name, new Expression[] { indexExpression1, indexExpression2, indexExpression3, indexExpression4, indexExpression5, indexExpression6, indexExpression7 }) | ||
{ | ||
} | ||
|
||
public CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5, TKey6, TKey7> Key(TKey1 key1, TKey2 key2, TKey3 key3, TKey4 key4, TKey5 key5, TKey6 key6, TKey7 key7) | ||
{ | ||
return new CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5, TKey6, TKey7>(key1, key2, key3, key4, key5, key6, key7); | ||
} | ||
} | ||
|
||
public class CompoundIndex<TRecord, TKey1, TKey2, TKey3, TKey4, TKey5, TKey6, TKey7, TKey8> : CompoundIndexBase<TRecord>, ICompoundIndex<TRecord, TKey1, TKey2, TKey3, TKey4, TKey5, TKey6, TKey7, TKey8> | ||
{ | ||
public CompoundIndex(ITableQuery<TRecord> table, string name, Expression<Func<TRecord, TKey1>> indexExpression1, Expression<Func<TRecord, TKey2>> indexExpression2, Expression<Func<TRecord, TKey3>> indexExpression3, Expression<Func<TRecord, TKey4>> indexExpression4, Expression<Func<TRecord, TKey5>> indexExpression5, Expression<Func<TRecord, TKey6>> indexExpression6, Expression<Func<TRecord, TKey7>> indexExpression7, Expression<Func<TRecord, TKey8>> indexExpression8) | ||
: base(table, name, new Expression[] { indexExpression1, indexExpression2, indexExpression3, indexExpression4, indexExpression5, indexExpression6, indexExpression7, indexExpression8 }) | ||
{ | ||
} | ||
|
||
public CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5, TKey6, TKey7, TKey8> Key(TKey1 key1, TKey2 key2, TKey3 key3, TKey4 key4, TKey5 key5, TKey6 key6, TKey7 key7, TKey8 key8) | ||
{ | ||
return new CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5, TKey6, TKey7, TKey8>(key1, key2, key3, key4, key5, key6, key7, key8); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RethinkDb | ||
{ | ||
public class CompoundIndexKey | ||
{ | ||
protected CompoundIndexKey(params object[] keyValues) | ||
{ | ||
this.KeyValues = keyValues; | ||
} | ||
|
||
public object[] KeyValues | ||
{ | ||
get; | ||
set; | ||
} | ||
} | ||
|
||
public class CompoundIndexKey<TKey1, TKey2> : CompoundIndexKey | ||
{ | ||
public CompoundIndexKey(TKey1 key1, TKey2 key2) | ||
: base(key1, key2) | ||
{ | ||
} | ||
} | ||
|
||
public class CompoundIndexKey<TKey1, TKey2, TKey3> : CompoundIndexKey | ||
{ | ||
public CompoundIndexKey(TKey1 key1, TKey2 key2, TKey3 key3) | ||
: base(key1, key2, key3) | ||
{ | ||
} | ||
} | ||
|
||
public class CompoundIndexKey<TKey1, TKey2, TKey3, TKey4> : CompoundIndexKey | ||
{ | ||
public CompoundIndexKey(TKey1 key1, TKey2 key2, TKey3 key3, TKey4 key4) | ||
: base(key1, key2, key3, key4) | ||
{ | ||
} | ||
} | ||
|
||
public class CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5> : CompoundIndexKey | ||
{ | ||
public CompoundIndexKey(TKey1 key1, TKey2 key2, TKey3 key3, TKey4 key4, TKey5 key5) | ||
: base(key1, key2, key3, key4, key5) | ||
{ | ||
} | ||
} | ||
|
||
public class CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5, TKey6> : CompoundIndexKey | ||
{ | ||
public CompoundIndexKey(TKey1 key1, TKey2 key2, TKey3 key3, TKey4 key4, TKey5 key5, TKey6 key6) | ||
: base(key1, key2, key3, key4, key5, key6) | ||
{ | ||
} | ||
} | ||
|
||
public class CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5, TKey6, TKey7> : CompoundIndexKey | ||
{ | ||
public CompoundIndexKey(TKey1 key1, TKey2 key2, TKey3 key3, TKey4 key4, TKey5 key5, TKey6 key6, TKey7 key7) | ||
: base(key1, key2, key3, key4, key5, key6, key7) | ||
{ | ||
} | ||
} | ||
|
||
public class CompoundIndexKey<TKey1, TKey2, TKey3, TKey4, TKey5, TKey6, TKey7, TKey8> : CompoundIndexKey | ||
{ | ||
public CompoundIndexKey(TKey1 key1, TKey2 key2, TKey3 key3, TKey4 key4, TKey5 key5, TKey6 key6, TKey7 key7, TKey8 key8) | ||
: base(key1, key2, key3, key4, key5, key6, key7, key8) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
rethinkdb-net/DatumConverters/CompoundIndexDatumConverterFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using RethinkDb.Spec; | ||
|
||
namespace RethinkDb.DatumConverters | ||
{ | ||
public class CompoundIndexDatumConverterFactory : AbstractDatumConverterFactory | ||
{ | ||
public static readonly CompoundIndexDatumConverterFactory Instance = new CompoundIndexDatumConverterFactory(); | ||
|
||
public override bool TryGet<T>(IDatumConverterFactory rootDatumConverterFactory, out IDatumConverter<T> datumConverter) | ||
{ | ||
if (rootDatumConverterFactory == null) | ||
throw new ArgumentNullException("rootDatumConverterFactory"); | ||
|
||
datumConverter = null; | ||
|
||
if (typeof(CompoundIndexKey).IsAssignableFrom(typeof(T))) | ||
{ | ||
var retval = Activator.CreateInstance( | ||
typeof(CompoundIndexKeyDatumConverterShim<>).MakeGenericType(typeof(T)), | ||
new object[] { rootDatumConverterFactory } | ||
); | ||
datumConverter = (IDatumConverter<T>)retval; | ||
} | ||
|
||
return datumConverter != null; | ||
} | ||
|
||
public class CompoundIndexKeyDatumConverterShim<T> : AbstractReferenceTypeDatumConverter<T> | ||
where T : CompoundIndexKey | ||
{ | ||
private readonly CompoundIndexKeyDatumConverter datumConverter; | ||
|
||
public CompoundIndexKeyDatumConverterShim(IDatumConverterFactory rootDatumConverterFactory) | ||
{ | ||
this.datumConverter = new CompoundIndexKeyDatumConverter(rootDatumConverterFactory); | ||
} | ||
|
||
#region implemented abstract members of AbstractReferenceTypeDatumConverter | ||
|
||
public override T ConvertDatum(Datum datum) | ||
{ | ||
throw new NotSupportedException("Converting back to a CompoundIndexKey object is not supported."); | ||
} | ||
|
||
public override Datum ConvertObject(T value) | ||
{ | ||
return datumConverter.ConvertObject(value); | ||
} | ||
|
||
#endregion | ||
} | ||
|
||
public class CompoundIndexKeyDatumConverter : AbstractReferenceTypeDatumConverter<CompoundIndexKey> | ||
{ | ||
private readonly IDatumConverterFactory rootDatumConverterFactory; | ||
|
||
public CompoundIndexKeyDatumConverter(IDatumConverterFactory rootDatumConverterFactory) | ||
{ | ||
this.rootDatumConverterFactory = rootDatumConverterFactory; | ||
} | ||
|
||
public override CompoundIndexKey ConvertDatum(Datum datum) | ||
{ | ||
throw new NotSupportedException("Converting back to a CompoundIndexKey object is not supported."); | ||
} | ||
|
||
public override Datum ConvertObject(CompoundIndexKey compoundIndexKey) | ||
{ | ||
if (compoundIndexKey == null) | ||
return new Datum { type = Datum.DatumType.R_NULL }; | ||
|
||
var retval = new Datum {type = Datum.DatumType.R_ARRAY}; | ||
foreach (var key in compoundIndexKey.KeyValues) | ||
{ | ||
var converter = rootDatumConverterFactory.Get(key.GetType()); | ||
retval.r_array.Add(converter.ConvertObject(key)); | ||
} | ||
|
||
return retval; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.