public async Task DeleteWithPredicate() { Client.Dispose(); WriteData(); string query = "from(bucket:\"" + _bucket.Name + "\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")"; _queryApi = Client.GetQueryApi(); var tables = await _queryApi.QueryAsync(query, _organization.Id); Assert.AreEqual(2, tables.Count); Assert.AreEqual(1, tables[0].Records.Count); Assert.AreEqual(5, tables[1].Records.Count); var location = "east"; var field = "water_level"; var predicate = $"location=\"{location}\" AND _field=\"{field}\""; _deleteApi = Client.GetDeleteApi(); await _deleteApi.Delete(DateTime.Now.AddHours(-1), DateTime.Now, predicate, _bucket, _organization); var tablesAfterDelete = await _queryApi.QueryAsync(query, _organization.Id); Assert.AreEqual(1, tablesAfterDelete.Count); Assert.AreEqual(5, tablesAfterDelete[0].Records.Count); await _deleteApi.Delete(DateTime.Now.AddHours(-1), DateTime.Now, "location = \"west\"", _bucket, _organization); var tablesAfterDelete2 = await _queryApi.QueryAsync(query, _organization.Id); Assert.AreEqual(0, tablesAfterDelete2.Count); }
/// <summary> /// Executes the Flux query against the InfluxDB 2.0 and synchronously map whole response /// to list of object with given type. /// /// <para> /// NOTE: This method is not intended for large query results. /// </para> /// </summary> /// <param name="query">the flux query to execute</param> /// <param name="org">specifies the source organization</param> /// <typeparam name="T">the type of measurement</typeparam> /// <returns>Measurements which are matched the query</returns> public List <T> QuerySync <T>(string query, string org) { Arguments.CheckNonEmptyString(query, nameof(query)); Arguments.CheckNonEmptyString(org, nameof(org)); return(QuerySync <T>(QueryApi.CreateQuery(query, QueryApi.DefaultDialect), org)); }
private void DbWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { Log.Trace("InfluxDbWorker:RunWorkerComplete"); dbQueryApi = null; if (dbClient != null) { dbClient.Dispose(); dbClient = null; } }
public new void SetUp() { var options = InfluxDBClientOptions.Builder .CreateNew() .Url(MockServerUrl) .AuthenticateToken("token") .Org("my-org") .Build(); _influxDbClient = InfluxDBClientFactory.Create(options); _influxDbClient.SetLogLevel(LogLevel.Body); _queryApi = _influxDbClient.GetQueryApi(); }
public async Task DefaultTagsMeasurement() { Client.Dispose(); Environment.SetEnvironmentVariable("measurement-datacenter", "LA"); ConfigurationManager.AppSettings["measurement-sensor.version"] = "1.23a"; var options = new InfluxDBClientOptions.Builder().Url(InfluxDbUrl) .AuthenticateToken(_token.ToCharArray()) .AddDefaultTag("id", "132-987-655") .AddDefaultTag("customer", "California Miner") .AddDefaultTag("env-var", "${env.measurement-datacenter}") .AddDefaultTag("sensor-version", "${measurement-sensor.version}") .Build(); Client = InfluxDBClientFactory.Create(options); var measurement1 = new H20Measurement { Location = "coyote_creek", Level = 2.927, Time = DateTime.UtcNow }; _writeApi = Client.GetWriteApi(); var listener = new WriteApiTest.EventListener(_writeApi); _writeApi.WriteMeasurement(_bucket.Name, _organization.Id, WritePrecision.Ms, measurement1); _writeApi.Flush(); listener.WaitToSuccess(); _queryApi = Client.GetQueryApi(); var tables = await _queryApi.QueryAsync( "from(bucket:\"" + _bucket.Name + "\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")", _organization.Id); Assert.AreEqual(1, tables.Count); Assert.AreEqual(1, tables[0].Records.Count); Assert.AreEqual("h2o", tables[0].Records[0].GetMeasurement()); Assert.AreEqual(2.927, tables[0].Records[0].GetValueByKey("level")); Assert.AreEqual("coyote_creek", tables[0].Records[0].GetValueByKey("location")); Assert.AreEqual("132-987-655", tables[0].Records[0].GetValueByKey("id")); Assert.AreEqual("California Miner", tables[0].Records[0].GetValueByKey("customer")); Assert.AreEqual("1.23a", tables[0].Records[0].GetValueByKey("sensor-version")); Assert.AreEqual("LA", tables[0].Records[0].GetValueByKey("env-var")); }
public async Task DefaultTagsPoint() { Client.Dispose(); Environment.SetEnvironmentVariable("point-datacenter", "LA"); ConfigurationManager.AppSettings["point-sensor.version"] = "1.23a"; var options = new InfluxDBClientOptions.Builder().Url(InfluxDbUrl) .AuthenticateToken(_token) .AddDefaultTag("id", "132-987-655") .AddDefaultTag("customer", "California Miner") .AddDefaultTag("env-var", "${env.point-datacenter}") .AddDefaultTag("sensor-version", "${point-sensor.version}") .Build(); Client = InfluxDBClientFactory.Create(options); var point = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 1); _writeApi = Client.GetWriteApi(); var listener = new WriteApiTest.EventListener(_writeApi); _writeApi.WritePoint(_bucket.Name, _organization.Id, point); _writeApi.Flush(); listener.WaitToSuccess(); _queryApi = Client.GetQueryApi(); var tables = await _queryApi.QueryAsync( $"from(bucket:\"{_bucket.Name}\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")", _organization.Id); Assert.AreEqual(1, tables.Count); Assert.AreEqual(1, tables[0].Records.Count); Assert.AreEqual("h2o_feet", tables[0].Records[0].GetMeasurement()); Assert.AreEqual(1, tables[0].Records[0].GetValueByKey("water_level")); Assert.AreEqual("west", tables[0].Records[0].GetValueByKey("location")); Assert.AreEqual("132-987-655", tables[0].Records[0].GetValueByKey("id")); Assert.AreEqual("California Miner", tables[0].Records[0].GetValueByKey("customer")); Assert.AreEqual("1.23a", tables[0].Records[0].GetValueByKey("sensor-version")); Assert.AreEqual("LA", tables[0].Records[0].GetValueByKey("env-var")); }
private void InitializeDb() { var dbConfig = WorkersManager.GetWorkersManager().Config; if (dbClient == null && dbConfig.IsDbConfigAvailable()) { try { Log.Info("InitializeDb"); dbClient = InfluxDBClientFactory.Create(dbConfig.Url, dbConfig.AuthToken.ToCharArray()); dbClient.Health(); dbQueryApi = dbClient.GetQueryApi(); } catch (Exception ex) { Log.Error("Db init error", ex); OnStatusChanged("DB Init Error: " + ex.Message); } } }
public async Task DefaultTagsConfiguration() { Client.Dispose(); var options = new InfluxDBClientOptions.Builder() .LoadConfig() .Url(InfluxDbUrl) .AuthenticateToken(_token) .Build(); Client = InfluxDBClientFactory.Create(options); var measurement1 = new H20Measurement { Location = "coyote_creek", Level = 2.927, Time = DateTime.UtcNow }; _writeApi = Client.GetWriteApi(); var listener = new WriteApiTest.EventListener(_writeApi); _writeApi.WriteMeasurement(_bucket.Name, _organization.Id, WritePrecision.Ms, measurement1); _writeApi.Flush(); listener.WaitToSuccess(); _queryApi = Client.GetQueryApi(); var tables = await _queryApi.QueryAsync( $"from(bucket:\"{_bucket.Name}\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")", _organization.Id); Assert.AreEqual(1, tables.Count); Assert.AreEqual(1, tables[0].Records.Count); Assert.AreEqual("h2o", tables[0].Records[0].GetMeasurement()); Assert.AreEqual(2.927, tables[0].Records[0].GetValueByKey("level")); Assert.AreEqual("coyote_creek", tables[0].Records[0].GetValueByKey("location")); Assert.AreEqual("132-987-655", tables[0].Records[0].GetValueByKey("id")); Assert.AreEqual("California Miner", tables[0].Records[0].GetValueByKey("customer")); Assert.AreEqual("v1.00", tables[0].Records[0].GetValueByKey("version")); }
public async Task Delete() { Client.Dispose(); WriteData(); string query = "from(bucket:\"" + _bucket.Name + "\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")"; _queryApi = Client.GetQueryApi(); var tables = await _queryApi.QueryAsync(query, _organization.Id); Assert.AreEqual(2, tables.Count); Assert.AreEqual(1, tables[0].Records.Count); Assert.AreEqual(5, tables[1].Records.Count); _deleteApi = Client.GetDeleteApi(); await _deleteApi.Delete(DateTime.Now.AddHours(-1), DateTime.Now, "", _bucket, _organization); var tablesAfterDelete1 = await _queryApi.QueryAsync(query, _organization.Id); Assert.AreEqual(0, tablesAfterDelete1.Count); }
public new async Task SetUp() { _organization = await FindMyOrg(); var retention = new BucketRetentionRules(BucketRetentionRules.TypeEnum.Expire, 3600); _bucket = await Client.GetBucketsApi() .CreateBucket(GenerateName("h2o"), retention, _organization); // // Add Permissions to read and write to the Bucket // var resource = new PermissionResource(PermissionResource.TypeEnum.Buckets, _bucket.Id, null, _organization.Id); var readBucket = new Permission(Permission.ActionEnum.Read, resource); var writeBucket = new Permission(Permission.ActionEnum.Write, resource); var loggedUser = await Client.GetUsersApi().Me(); Assert.IsNotNull(loggedUser); var authorization = await Client.GetAuthorizationsApi() .CreateAuthorization(await FindMyOrg(), new List <Permission> { readBucket, writeBucket }); _token = authorization.Token; Client.Dispose(); var options = new InfluxDBClientOptions.Builder().Url(InfluxDbUrl).AuthenticateToken(_token.ToCharArray()) .Org(_organization.Id).Bucket(_bucket.Id).Build(); Client = InfluxDBClientFactory.Create(options); _queryApi = Client.GetQueryApi(); }
public void OnCreateWithConfiguration() { configuratiopn = GetClientConfig(); queryApiTest = new QueryApi(configuratiopn); Assert.NotNull(queryApiTest.Configuration); }
public InfluxReader(IInfluxDbConnection connection) { _queryApi = connection.Client.GetQueryApi(); }
public bool Execute(string importPath, string practiceId, List <Query> queryTemplates) { var patientApi = new PatientApi(Config.PopHealthUser, Config.PopHealthPassword, Config.PopHealthBaseUrl); var practiceApi = new PracticeApi(Config.PopHealthUser, Config.PopHealthPassword, Config.PopHealthBaseUrl); var queryApi = new QueryApi(Config.PopHealthUser, Config.PopHealthPassword, Config.PopHealthBaseUrl); try { if (Path.HasExtension(importPath)) { if (Path.GetExtension(importPath).Equals(".zip", StringComparison.CurrentCultureIgnoreCase)) { Log.Write(string.Format("Searching for practice with alternate Id {0}", practiceId)); var practices = practiceApi.SearchForPracticesByAlternateId(practiceId); if (practices == null || practices.Count == 0) { var responseMessage = string.Format("No practices were found with alternate Id {0}.", practiceId); throw new Exception(responseMessage); } if (practices.Count > 1) { var responseMessage = string.Format("{0} practices were found with alternate Id {1}.", practices.Count, practiceId); throw new Exception(responseMessage); } var practice = practiceApi.Get(practices.First().Id); Log.Write("Completed searching for practice"); if (practice.PatientCount.HasValue && practice.PatientCount.Value > 0) { Log.Write(string.Format("Removing {0} patients", practices.First().PatientCount)); practiceApi.RemovePatients(practices.First().Id); Log.Write("Completed removing patients"); } Log.Write("Beginning patient archive import"); patientApi.UploadArchive(importPath, practice); Log.Write("Successfully finished patient archive import"); //System.Threading.Thread.Sleep(10000); //Log.Write("Beginning query cache setup"); //foreach (var template in queryTemplates) //{ // if (practice.Providers != null) // { // Query query = null; // foreach (var provider in practice.Providers) // { // query = new Query(template) { Providers = new[] { provider } }; // queryApi.Add(query); // } // query = new Query(template) { Providers = new[] { practice.ProviderId } }; // queryApi.Add(query); // } //} //Log.Write("Successfully finished loading query cache jobs"); } else { Log.Write("Unknown file extension. This job will exit with no records imported."); } } else { Log.Write("No file extension could be found. This job will exit with no records imported."); } } catch (Exception exc) { Console.WriteLine("The following error was raised:\r\n {0}\r\n\r\nSee {1} for more details.", exc.Message, Log.LogPath); Log.WriteException(exc); return(false); } return(true); }
public void OnCreateWithoutPath() { queryApiTest = new QueryApi(); Assert.NotNull(queryApiTest.Configuration); }
public void OnCreate() { queryApiTest = new QueryApi(this.basePath); Assert.NotNull(queryApiTest.Configuration); }
public async Task Delete() { Client.Dispose(); Environment.SetEnvironmentVariable("point-datacenter", "LA"); ConfigurationManager.AppSettings["point-sensor.version"] = "1.23a"; var options = new InfluxDBClientOptions.Builder().Url(InfluxDbUrl) .AuthenticateToken(_token.ToCharArray()) .AddDefaultTag("id", "132-987-655") .AddDefaultTag("customer", "California Miner") .AddDefaultTag("env-var", "${env.point-datacenter}") .AddDefaultTag("sensor-version", "${point-sensor.version}") .Build(); Client = InfluxDBClientFactory.Create(options); var point = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 1); var point2 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 2); var point3 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 3); var point4 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 4); var point5 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 5); var point6 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 6); _writeApi = Client.GetWriteApi(); var listener = new WriteApiTest.EventListener(_writeApi); _writeApi.WritePoint(_bucket.Name, _organization.Id, point); _writeApi.Flush(); listener.WaitToSuccess(); _writeApi.WritePoint(_bucket.Name, _organization.Id, point2); _writeApi.Flush(); listener.WaitToSuccess(); _writeApi.WritePoint(_bucket.Name, _organization.Id, point3); _writeApi.Flush(); listener.WaitToSuccess(); _writeApi.WritePoint(_bucket.Name, _organization.Id, point4); _writeApi.Flush(); listener.WaitToSuccess(); _writeApi.WritePoint(_bucket.Name, _organization.Id, point5); _writeApi.Flush(); listener.WaitToSuccess(); _writeApi.WritePoint(_bucket.Name, _organization.Id, point6); _writeApi.Flush(); listener.WaitToSuccess(); string query = "from(bucket:\"" + _bucket.Name + "\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")"; _queryApi = Client.GetQueryApi(); var tables = await _queryApi.QueryAsync(query, _organization.Id); Assert.AreEqual(1, tables.Count); Assert.AreEqual(6, tables[0].Records.Count); _deleteApi = Client.GetDeleteApi(); await _deleteApi.Delete(DateTime.Now.AddSeconds(-1), DateTime.Now, "", _bucket, _organization); var tablesAfterDelete = await _queryApi.QueryAsync(query, _organization.Id); Assert.AreNotEqual(0, tablesAfterDelete.Count); await _deleteApi.Delete(DateTime.Now.AddHours(-1), DateTime.Now, "", _bucket, _organization); var tablesAfterDelete2 = await _queryApi.QueryAsync(query, _organization.Id); Assert.AreEqual(0, tablesAfterDelete2.Count); }
public void Init() { instance = new QueryApi(); }