2424import java .io .IOException ;
2525import java .io .StringReader ;
2626import java .time .Instant ;
27+ import java .util .ArrayList ;
28+ import java .util .Arrays ;
29+ import java .util .HashMap ;
2730import java .util .List ;
31+ import java .util .Map ;
2832
2933import com .influxdb .Cancellable ;
3034import com .influxdb .query .InfluxQLQueryResult ;
3135import org .assertj .core .api .Assertions ;
3236import org .junit .jupiter .api .Test ;
37+ import org .junit .platform .engine .TestTag ;
3338
3439class InfluxQLQueryApiImplTest {
3540
@@ -44,6 +49,55 @@ public boolean isCancelled() {
4449 }
4550 };
4651
52+ @ Test
53+ void readInfluxQLResultWithTagCommas () throws IOException {
54+ InfluxQLQueryResult .Series .ValueExtractor extractValue = (columnName , rawValue , resultIndex , seriesName ) -> {
55+ // System.out.println("DEBUG columnName: " + columnName + ", rawValue: " + rawValue + ", resultIndex: " + resultIndex + ", seriesName: " + seriesName);
56+ if (resultIndex == 0 && seriesName .equals ("data1" )){
57+ switch (columnName ){
58+ case "time" : return Instant .ofEpochSecond (Long .parseLong (rawValue ));
59+ case "first" : return Double .valueOf (rawValue );
60+ //case "tags": return rawValue;
61+ }
62+ }
63+ return rawValue ;
64+ };
65+
66+ // Cheb,CZ should be \"Cheb,CZ\" a single tag value
67+ // double quotes should work - from raw sample results commas should always be escaped
68+ StringReader reader = new StringReader ("name,tags,time,first\n "
69+ + "data1,\" location=Cheb_CZ\" ,1483225200,42\n "
70+ + "data1,\" region=us-east-1,host=server1\" ,1483225200,13.57\n "
71+ // + "data1,\"location=Cheb,CZ\",1483225200,42\n" // invalid - comma in value should be escaped
72+ // + "data1,\"location=Cheb, CZ\",1483225200,42\n" // invalid - comma and space in value should be escaped
73+ + "data1,\" location=Cheb\\ ,\\ CZ\" ,1483225200,42\n "
74+ + "data1,\" location=Cheb_CZ,branch=Munchen_DE\" ,1483225200,42\n "
75+ + "data1,\" location=Cheb\\ ,\\ CZ,branch=Munchen\\ ,\\ DE\" ,1483225200,42\n "
76+ + "data1,\" model\\ ,\\ uin=C3PO\" ,1483225200,42\n "
77+ + "data1,\" model\\ ,\\ uin=Droid\\ , C3PO\" ,1483225200,42\n "
78+ + "data1,\" location=Cheb\\ ,\\ CZ,branch=Munchen\\ ,\\ DE\" ,1483225200,42\n "
79+ + "data1,\" model\\ ,\\ uin=Droid\\ ,\\ C3PO,location=Cheb\\ ,\\ CZ,branch=Munchen\\ ,\\ DE\" ,1483225200,42\n "
80+ + "data1,\" silly\\ ,long\\ ,tag=a\\ ,b\\ ,\\ c\\ ,\\ d\" ,1483225200,42\n "
81+ + "\n "
82+ + "name,tags,time,usage_user,usage_system\n "
83+ + "cpu,\" region=us\\ ,\\ east-1,host\\ ,\\ name=ser\\ ,\\ ver1\" ,1483225200,13.57,1.4\n "
84+ );
85+
86+ // TODO meaningful asserts
87+ InfluxQLQueryResult result = InfluxQLQueryApiImpl .readInfluxQLResult (reader , NO_CANCELLING , extractValue );
88+ List <InfluxQLQueryResult .Result > results = result .getResults ();
89+ // System.out.println("DEBUG results\n" + results.get(0).getSeries().get(0).getValues().get(0).getValueByKey("tags"));
90+ }
91+
92+ /*
93+ Sample response 1 - note escaped commas
94+ name,tags,time,fVal,iVal,id,location,"location\,boo",model,"model\,uin",sVal
95+ zaphrod_b,,1773307528202967039,26.54671,-6922649068284626682,bar,Harfa,,R2D2,,FOO
96+ zaphrod_b,,1773322199131651270,26.54671,-6922649068284626682,bar,,Harfa,R2D2,,FOO
97+ zaphrod_b,,1773322228235655514,26.54671,-6922649068284626682,bar,,"Harfa\,\ Praha",R2D2,,FOO
98+ zaphrod_b,,1773322254827374192,26.54671,-6922649068284626682,bar,,"Harfa\,\ Praha",,R2D2,FOO
99+ */
100+
47101 @ Test
48102 void readInfluxQLResult () throws IOException {
49103 InfluxQLQueryResult .Series .ValueExtractor extractValues = (columnName , rawValue , resultIndex , seriesName ) -> {
0 commit comments