internal static async Task ExampleAsync(NameValueCollection settings) { using (var client = new HdInsightClient(settings["ClusterName"], settings["ClusterUsername"], settings["ClusterPassword"])) using (var cosmos = new CosmosDbLivySession(client, CosmosSettings.GetSettings(settings), CosmosExampleSessionConfiguration.GetConfiguration())) { const string sql = "SELECT contactIdentifier AS ContactIdentifier, COUNT(*) AS Count FROM cosmos GROUP BY contactIdentifier ORDER BY COUNT(*) DESC LIMIT 20"; var results = await cosmos.QuerySparkSqlAsync <Result>(sql); results.ToList().ForEach(t => Console.WriteLine($"{t.ContactIdentifier}:{t.Count}")); } Console.ReadKey(); }
public async Task <CosmosDbLivySession> GetSessionAsync() { var availableSession = await GetAvailableSessionFromPoolAsync().ConfigureAwait(false); if (availableSession != null) { return(availableSession); } if (_sessions.Count >= _maxSessions) { return(await _sessions.FirstCompletedAsync(t => t.WaitForSessionAsync()).ConfigureAwait(false)); } var session = new CosmosDbLivySession(_client, _cosmosCollectionSettings, _livySessionConfiguration); _sessions.Add(session); return(session); }
internal static async Task ExampleAsync(NameValueCollection settings) { using (var client = new HdInsightClient(settings["ClusterName"], settings["ClusterUsername"], settings["ClusterPassword"])) using (var cosmos = new CosmosDbLivySession(client, CosmosSettings.GetSettings(settings), CosmosExampleSessionConfiguration.GetConfiguration())) { const string sparkSql = "SELECT contactIdentifier AS Item1, COUNT(*) AS Item2 FROM cosmos GROUP BY contactIdentifier ORDER BY COUNT(*) DESC LIMIT 20"; const string cosmosSqlQuery = "SELECT cosmos.contactIdentifier FROM cosmos"; // Create session and warm up await cosmos.QuerySparkSqlAsync <(int, decimal)>(sparkSql, cosmosSqlQuery); var query = (Func <Task <IEnumerable <(int, decimal)> > >)(() => cosmos.QuerySparkSqlAsync <(int, decimal)>(sparkSql, cosmosSqlQuery)); var result = await query.RunAndTimeExecution(); Console.WriteLine($"Elpsed: {result.Elapsed}"); result.Result.ToList().ForEach(t => Console.WriteLine($"{t.Item1}:{t.Item2}")); } Console.ReadKey(); }