public KSqlJoinsVisitor(StringBuilder stringBuilder, KSqlDBContextOptions contextOptions, QueryContext queryContext, KSqlQueryMetadata queryMetadata) : base(stringBuilder, queryMetadata) { this.contextOptions = contextOptions ?? throw new ArgumentNullException(nameof(contextOptions)); this.queryContext = queryContext ?? throw new ArgumentNullException(nameof(queryContext)); this.queryMetadata = queryMetadata ?? throw new ArgumentNullException(nameof(queryMetadata)); }
public void QueriesFromSameCreateStreamSetShouldNotAffectEachOther() { //Arrange var options = new KSqlDBContextOptions(TestParameters.KsqlDBUrl) { ShouldPluralizeFromItemName = false }; var context = new TransactionsDbProvider(options); var grouping1 = context.CreateQueryStream <Transaction>("authorization_attempts_1") .GroupBy(c => c.CardNumber) .Select(g => new { CardNumber = g.Key, Count = g.Count() }); var grouping2 = context.CreateQueryStream <Transaction>("authorization_attempts_2") .GroupBy(c => c.CardNumber) .Select(g => new { CardNumber = g.Key, Count = g.Count() }); var take = grouping2.Take(2); //Act var ksql1 = grouping1.ToQueryString(); var ksql2 = grouping2.ToQueryString(); var ksqlTake = take.ToQueryString(); //Assert ksql1.Should().BeEquivalentTo("SELECT CardNumber, COUNT(*) Count FROM authorization_attempts_1 GROUP BY CardNumber EMIT CHANGES;"); ksql2.Should().BeEquivalentTo("SELECT CardNumber, COUNT(*) Count FROM authorization_attempts_2 GROUP BY CardNumber EMIT CHANGES;"); ksqlTake.Should().BeEquivalentTo("SELECT CardNumber, COUNT(*) Count FROM authorization_attempts_2 GROUP BY CardNumber EMIT CHANGES LIMIT 2;"); }
public override void TestInitialize() { base.TestInitialize(); var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl); KSqlDBContext = new KSqlDBContext(contextOptions); }
public KSqlDBContext(KSqlDBContextOptions contextOptions, ILoggerFactory loggerFactory = null) : base(contextOptions, loggerFactory) { this.contextOptions = contextOptions ?? throw new ArgumentNullException(nameof(contextOptions)); KSqlDBQueryContext = new KSqlDBContextQueryDependenciesProvider(contextOptions); }
public static async Task Main(string[] args) { var ksqlDbUrl = @"http:\\localhost:8088"; var contextOptions = new KSqlDBContextOptions(ksqlDbUrl); await using var context = new KSqlDBContext(contextOptions); using var disposable = context.CreateQueryStream <Tweet>() .Where(p => p.Message != "Hello world" || p.Id == 1) .Where(c => K.Functions.Like(c.Message.ToLower(), "%ALL%".ToLower())) .Where(p => p.RowTime >= 1510923225000) //AND RowTime >= 1510923225000 .Select(l => new { l.Id, l.Message, l.RowTime }) .Take(2) // LIMIT 2 .ToObservable() // client side processing starts here lazily after subscription .ObserveOn(TaskPoolScheduler.Default) .Subscribe(onNext: tweetMessage => { Console.WriteLine($"{nameof(Tweet)}: {tweetMessage.Id} - {tweetMessage.Message}"); Console.WriteLine(); }, onError: error => { Console.WriteLine($"Exception: {error.Message}"); }, onCompleted: () => Console.WriteLine("Completed")); Console.WriteLine("Press any key to stop the subscription"); Console.ReadKey(); Console.WriteLine("Subscription completed"); }
public override void TestInitialize() { base.TestInitialize(); ContextOptions = new KSqlDBContextOptions(KSqlDbRestApiProvider.KsqlDbUrl); Context = new KSqlDBContext(ContextOptions); }
public override void TestInitialize() { base.TestInitialize(); contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl); queryContext = new QueryContext(); ClassUnderTest = new KSqlQueryGenerator(contextOptions); }
public async Task TestInitialize() { contextOptions = new KSqlDBContextOptions(KSqlDbRestApiProvider.KsqlDbUrl); context = new KSqlDBContext(contextOptions); pullQueryProvider = new SensorsPullQueryProvider(); await pullQueryProvider.ExecuteAsync(); }
public override void TestInitialize() { base.TestInitialize(); ContextOptions = new KSqlDBContextOptions(KSqlDbRestApiProvider.KsqlDbUrl) { ShouldPluralizeFromItemName = false }; Context = new KSqlDBContext(ContextOptions); }
internal KSqlDBContextOptions Clone() { var options = new KSqlDBContextOptions(Url) { ShouldPluralizeFromItemName = ShouldPluralizeFromItemName, QueryParameters = ((QueryParameters)QueryParameters).Clone(), QueryStreamParameters = QueryStreamParameters.Clone() as QueryStreamParameters }; return(options); }
private static async Task ToQueryStringExample(string ksqlDbUrl) { var contextOptions = new KSqlDBContextOptions(ksqlDbUrl); await using var context = new KSqlDBContext(contextOptions); var ksql = context.CreateQueryStream <Person>().ToQueryString(); //prints SELECT * FROM People EMIT CHANGES; Console.WriteLine(ksql); }
private static IDisposable KQueryWithObserver(string ksqlDbUrl) { var contextOptions = new KSqlDBContextOptions(ksqlDbUrl); var context = new KSqlDBContext(contextOptions); var subscription = context.CreateQueryStream <Tweet>() .Where(p => p.Message != "Hello world" && p.Id != 1) .Take(2) .Subscribe(new TweetsObserver()); return(subscription); }
private static IDisposable ToObservableExample(string ksqlDbUrl) { var contextOptions = new KSqlDBContextOptions(ksqlDbUrl); var context = new KSqlDBContext(contextOptions); var subscriptions = context.CreateQueryStream <Tweet>() .ToObservable() .Delay(TimeSpan.FromSeconds(2)) // IObservable extensions .Subscribe(new TweetsObserver()); return(subscriptions); }
public static async Task ClassInitialize(TestContext testContext) { contextOptions = new KSqlDBContextOptions(KSqlDbRestApiProvider.KsqlDbUrl); context = new KSqlDBContext(contextOptions); pullQueryProvider = new SensorsPullQueryProvider(); await pullQueryProvider.ExecuteAsync(); await Task.Delay(TimeSpan.FromSeconds(6)); }
protected virtual void OnConfigureServices(IServiceCollection serviceCollection, KSqlDBContextOptions contextOptions) { if (loggerFactory != null) { serviceCollection.TryAddSingleton(_ => loggerFactory); Logger = loggerFactory.CreateLogger(LoggingCategory.Name); serviceCollection.TryAddSingleton(Logger); } serviceCollection.RegisterKSqlDbContextDependencies(contextOptions); }
private static async Task GroupBy() { var ksqlDbUrl = @"http:\\localhost:8088"; var contextOptions = new KSqlDBContextOptions(ksqlDbUrl); contextOptions.QueryStreamParameters["auto.offset.reset"] = "latest"; await using var context = new KSqlDBContext(contextOptions); context.CreateQueryStream <Tweet>() .GroupBy(c => c.Id) .Select(g => new { Id = g.Key, Count = g.Count() }) .Subscribe(count => { Console.WriteLine($"{count.Id} Count: {count.Count}"); Console.WriteLine(); }, error => { Console.WriteLine($"Exception: {error.Message}"); }, () => Console.WriteLine("Completed")); context.CreateQueryStream <Tweet>() .GroupBy(c => c.Id) .Select(g => g.Count()) .Subscribe(count => { Console.WriteLine($"Count: {count}"); Console.WriteLine(); }, error => { Console.WriteLine($"Exception: {error.Message}"); }, () => Console.WriteLine("Completed")); context.CreateQueryStream <Tweet>() .GroupBy(c => c.Id) .Select(g => new { Count = g.Count() }) .Subscribe(count => { Console.WriteLine($"Count: {count}"); Console.WriteLine(); }, error => { Console.WriteLine($"Exception: {error.Message}"); }, () => Console.WriteLine("Completed")); //Sum var subscription = context.CreateQueryStream <Tweet>() .GroupBy(c => c.Id) //.Select(g => g.Sum(c => c.Id)) .Select(g => new { Id = g.Key, MySum = g.Sum(c => c.Id) }) .Subscribe(sum => { Console.WriteLine($"{sum}"); Console.WriteLine(); }, error => { Console.WriteLine($"Exception: {error.Message}"); }, () => Console.WriteLine("Completed")); var groupBySubscription = context.CreateQueryStream <IoTSensorChange>("sqlserversensors") .GroupBy(c => new { c.Op, c.After !.Value })
public void Initialize() { var ksqlDbUrl = @"http:\\localhost:8088"; var httpClientFactory = new HttpClientFactory(new Uri(ksqlDbUrl)); restApiClient = new KSqlDbRestApiClient(httpClientFactory); var contextOptions = new KSqlDBContextOptions(KSqlDbRestApiProvider.KsqlDbUrl) { ShouldPluralizeFromItemName = true }; Context = new KSqlDBContext(contextOptions); }
public void CreateStreamSet_Subscribe_ProcessingGuarantee() { //Arrange var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl); contextOptions.SetProcessingGuarantee(ProcessingGuarantee.ExactlyOnce); var context = new TestableDbProvider <string>(contextOptions); //Act var subscription = context.CreateQueryStream <string>().Subscribe(_ => {}); //Assert context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c[KSqlDbConfigs.ProcessingGuarantee] == "exactly_once"), It.IsAny <CancellationToken>()), Times.Once); }
public void SetAutoOffsetReset_Subscribe_ProcessingGuarantee() { //Arrange var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl); contextOptions.SetAutoOffsetReset(AutoOffsetReset.Latest); var context = new TestableDbProvider <string>(contextOptions); //Act var subscription = context.CreateQueryStream <string>().Subscribe(_ => {}); //Assert context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c["auto.offset.reset"] == "latest"), It.IsAny <CancellationToken>()), Times.Once); }
public void CreateStreamSet_Subscribe_KSqlQueryGenerator() { //Arrange var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl); contextOptions.QueryStreamParameters["auto.offset.reset"] = "latest"; var context = new TestableDbProvider <string>(contextOptions); //Act var subscription = context.CreateQueryStream <string>().Subscribe(_ => {}, e => {}); //Assert context.KSqldbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(parameters => parameters["auto.offset.reset"] == "latest"), It.IsAny <CancellationToken>()), Times.Once); }
internal IServiceScopeFactory Initialize(KSqlDBContextOptions contextOptions) { if (!wasConfigured) { wasConfigured = true; RegisterDependencies(contextOptions); ServiceProvider = ServiceCollection.BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true }); } var serviceScopeFactory = ServiceProvider.GetService <IServiceScopeFactory>(); return(serviceScopeFactory); }
public void WithOffsetResetPolicy_Subscribe_QueryOptionsWereTakenFromContext() { //Arrange var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl); var context = new TestableDbProvider <string>(contextOptions) { RegisterKSqlQueryGenerator = false }; //Act var subscription = context.CreateQueryStream <string>().WithOffsetResetPolicy(AutoOffsetReset.Latest).Subscribe(_ => {}); //Assert // context.KSqldbProviderMock.Verify(c => c.Run<string>(It.Is<IQueryParameters>(c => c["auto.offset.reset"] == "latest"), It.IsAny<CancellationToken>()), Times.Once); context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c.AutoOffsetReset == AutoOffsetReset.Latest), It.IsAny <CancellationToken>()), Times.Once); subscription.Dispose(); }
public void CreateStreamSet_Subscribe_QueryOptionsWereTakenFromContext() { //Arrange var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl) { QueryStreamParameters = { ["auto.offset.reset"] = "latest" } }; var context = new TestableDbProvider <string>(contextOptions); //Act var subscription = context.CreateQueryStream <string>().Subscribe(_ => {}); //Assert context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c["auto.offset.reset"] == "latest"), It.IsAny <CancellationToken>()), Times.Once); subscription.Dispose(); }
public MoviesKSqlDbContext(KSqlDBContextOptions contextOptions, ILoggerFactory loggerFactory = null) : base(contextOptions, loggerFactory) { }
protected override void OnConfigureServices(IServiceCollection serviceCollection, KSqlDBContextOptions contextOptions) { base.OnConfigureServices(serviceCollection, contextOptions); serviceCollection.TryAddScoped <IKSqlDbProvider, KSqlDbQueryStreamProvider>(); serviceCollection.TryAddSingleton <IKSqlDbParameters>(contextOptions.QueryStreamParameters); }
protected override void OnConfigureServices(IServiceCollection serviceCollection, KSqlDBContextOptions options) { serviceCollection.AddSingleton(httpClientFactory); base.OnConfigureServices(serviceCollection, options); }
public TestableDbProvider(KSqlDBContextOptions contextOptions) : base(contextOptions) { InitMocks(); }
protected override void OnConfigureServices(IServiceCollection serviceCollection, KSqlDBContextOptions options) { serviceCollection.AddSingleton(KSqldbProviderMock.Object); if (RegisterKSqlQueryGenerator) { serviceCollection.AddSingleton(KSqlQueryGenerator.Object); } base.OnConfigureServices(serviceCollection, options); }
public KSqlJoinsVisitor(StringBuilder stringBuilder, KSqlDBContextOptions contextOptions, QueryContext queryContext) : base(stringBuilder, useTableAlias: false) { this.contextOptions = contextOptions ?? throw new ArgumentNullException(nameof(contextOptions)); this.queryContext = queryContext ?? throw new ArgumentNullException(nameof(queryContext)); }
public KSqlDBContextQueryDependenciesProvider(KSqlDBContextOptions kSqlDbContextOptions) : base(kSqlDbContextOptions) { }