Influxdb2 Merge one measurement into another using flux - flux

I set up influxdb2 to collect data into a measurement "meas0".
Now I imported historic data using the line protocol, unfortunately I did a mistake with the target measurement and it went into a second series "meas1". The structure and names regarding the fields and tags are the same.
I found a solution on stackoverflox for influxdb1 using fluxQL. I understand that this is not available for fresh influxdb2 installations!?
So can someone show me how to merge "meas1" into "meas0" and get rid of "meas0"?

I found the following solution here:
https://community.influxdata.com/t/how-to-copy-data-between-measurements/22582/4
from(bucket: "example-bucket")
|> range(start: 2021-11-21T00:00:00Z, stop: 2021-11-22T00:00:00Z)
|> filter(fn: (r) => r._measurement == "meas0")
|> set(key: "_measurement", value: "meas1")
|> to(bucket: "example-bucket")
There is also a way using map but I cannot find the reference aghain.
Finally, to delete a whole measurement on can use "influx delete --bucket --start --stop --predicate '_measurement="meas0"'

Related

StringInderxer and One hot encoding in SparkR

I am trying to convert string variable in SparkR to numeric by using one hot encoding concept and using stringindexer on below code:
df<-ft_string_indexer(spark_df,input_col=cluster_group,output_col=new)
However, I am getting below error:
no applicable method for 'ft_string_indexer' applied to an object of class "SparkDataFrame"
Any idea on correct code for stringindexer and Onehotencoding in SparkR?
First, ft_string_indexer() is for sparklyr not sparkR. For differences between the two see here. In general, sparklyr is better for ML so I'd recommend moving to sparklyr if you can.
Second, it is worth noting that SparkR uses onehotencoder in the background for all of its ML. This is noted here. So, you maybe able to get away without doing it depending on what your model.
I couldn't find a SparkR function that does the same thing as ft_string_indexer() exactly, but you could use encode. This should hold up in whatever ML you're doing but without an example I can't be sure. The following is taken from the SparkR documentation on encode:
df <- createDataFrame(as.data.frame(Titanic, stringsAsFactors = FALSE))
tmp <- mutate(df, s1 = encode(df$Class, "UTF-8"))
tmp2 <- mutate(tmp, s2 = base64(tmp$s1),
s3 = decode(tmp$s1, "UTF-8"),
s4 = soundex(tmp$Sex))

Get last value from incomplete observable

There is an incomplete observable which can have or not have a replay of n values. I would like to get the last value from it - or just the next one if there is none yet.
This works for first available value with first() and take(1) (example):
possiblyReplayedIncomplteObservable.first().toPromise().then(val => ...);
But for the last value both last() and takeLast(1) wait for observable completion - not the desirable behaviour here.
How can this be solved? Is there a specific operator for that?
I had a solution for ReplaySubject(2) that 'drains' the sequence to get the latest element and if the sequence is empty simply takes the last element, yet, it was cumbersome and did not scale well (for example, if you decide to increase the replay size to 3). I then remembered that Replay/Behavior subjects tend to be hard to manage when they are piped. The simplest solution to that is to create a 'shadow' sequence and pipe your ReplaySubject into it (instead of creating it by transformation/operation on your ReplaySubject), hence:
var subject$ = new Rx.ReplaySubject(3);
var lastValue$ = new Rx.ReplaySubject(1);
subject$.subscribe(lastValue$); // short hand for subject$.subscribe(v => lastValue$.next(v))
lastValue$.take(1).toPromise().then(...);
========== Old solutions, ignoring the ReplaySubject(2) =================
After reading the comment below, the correct code is:
Rx.Observable.combineLatest(possiblyReplayedIncomplteObservable).take(1).subscribe(...)
and not
Rx.Observable.combineLatest(possiblyReplayedIncomplteObservable).subscribe(...)
This is due to the fact the promise is a "one time" observable. I think the toPromise() code resolves the result only on completion.
The take(1) will not affect your original stream since it operates on the new stream which is created by combineLatest.
And actually, the simplest way is:
possiblyReplayedIncomplteObservable.take(1).toPromise().then(...)

result expanded to maximum (more) on wolfram alpha query

I am using mathematica to query wolfram alpha for a query. for that purpose I use:
WolframAlpha["prime minister of france", "PodPlaintext"]
I took the options from here: http://reference.wolfram.com/language/ref/WolframAlpha.html
My problem is that I need info that is hidden at first and is located under the more option on the page. I was unable to find a way to query the full data (after more was clicked) from the mathematica.
Any ideas how to achieve it?
For anyone who encounters this problem in the future, I will post the answer in case someone else will have this problem. You have to use the more option combined with asynchronous and change the timeout:
WolframAlpha["prime minister of france", Asynchronous -> True,
PodStates -> {"More"}, TimeConstraint -> 20000]

groupingBy operation in Java-8

I'm trying to re-write famous example of Spark's text classification (http://chimpler.wordpress.com/2014/06/11/classifiying-documents-using-naive-bayes-on-apache-spark-mllib/) on Java 8.
I have a problem - in this code I'm making some data preparations for getting idfs of all words in all files:
termDocsRdd.collect().stream().flatMap(doc -> doc.getTerms().stream()
.map(term -> new ImmutableMap.Builder<String, String>()
.put(doc.getName(),term)
.build())).distinct()
And I'm stuck on the groupBy operation. (I need to group this by term, so each term must be a key and the value must be a sequence of documents).
In Scala this operation looks very simple - .groupBy(_._2).
But how can I do this in Java?
I tried to write something like:
.groupingBy(term -> term, mapping((Document) d -> d.getDocNameContainsTerm(term), toList()));
but it's incorrect...
Somebody knows how to write it in Java?
Thank You very much.
If I understand you correctly, you want to do something like this:
(import static java.util.stream.Collectors.*;)
Map<Term, Set<Document>> collect = termDocsRdd.collect().stream().flatMap(
doc -> doc.getTerms().stream().map(term -> new AbstractMap.SimpleEntry<>(doc, term)))
.collect(groupingBy(Map.Entry::getValue, mapping(Map.Entry::getKey, toSet())));
The use of Map.Entry/ AbstractMap.SimpleEntry is due to the absence of a standard Pair<K,V> class in Java-8. Map.Entry implementations can fulfill this role but at the cost of having unintuitive and verbose type and method names (regarding the task of serving as Pair implementation).
If you are using the current Eclipse version (I tested with LunaSR1 20140925) with its limited type inference, you have to help the compiler a little bit:
Map<Term, Set<Document>> collect = termDocsRdd.collect().stream().flatMap(
doc -> doc.getTerms().stream().<Map.Entry<Document,Term>>map(term -> new AbstractMap.SimpleEntry<>(doc, term)))
.collect(groupingBy(Map.Entry::getValue, mapping(Map.Entry::getKey, toSet())));

Get the line-number that throws the error in Tampermonkey?

When developing a script for Tampermonkey, I don't get the line-number that has errors, just what error it is. Is it possible to get the number somehow?
The way I have my configurations, I see everything. Here is how:
TamperMonkey Dashboard |> Settings Tab |> General |> Config mode: |> Select Advanced
Debug scripts: |> Checked
Logging level: |> Select Error (dealer's choice here, I chose this but you can decide)

Resources