I am trying to display the result of a Mondrian query using JPivot. Many examples are showing how to use the tag library for JSP but I need to use the Java API, I looked at the documentation but I cannot understand how to use it to display the results in the table. Here is my code
Query query = connection.parseQuery(mdxQuery);
Result result = connection.execute(query);
result.print(new PrintWriter(System.out,true));
I would like to know if I can use the result object to build the jpivot table.
Thanks in advance!
First of all, using JPivot
is a pretty bad idea.
It was discontinued back in 2008.
There is a good project which is intended to replace the JPivot called Pivot4j. Despite it is currently under development (0.8 -> 0.9 version), Pivot4j can actually do the business.
However, if we're talking about your case:
result.print(new PrintWriter(System.out,true));
This string prints the HTML code with OLAP cube into your System.out.
You can write the HTML code in some output stream (like FileOuputStream), and then display it.
OutputStream out = new FileOutputStream("result.html");
result.print(new PrintWriter(out, true));
//then display this file in a browser
However, if you want to have the same interface as in JPivot, I don't think there is an easy way to do it without .jsp. In these case I strongly recommend you to try Pivot4j.
Good luck!
Related
I am using MLeap to run a Pyspark logistic regression model in a java program. Once I run the pipeline I am able to get a DefaultLeapFrame object with one row Stream(Row(1.3,12,3.6,DenseTensor([D#538613b3,List(2)),1.0), ?).
But I am not sure how to actually inspect the DenseTensor object. When I use getTensor(3) on this row I get an object. I am not familiar with Scala but that seems to be how this is meant to be interacted with. In Java how can I get the values within this DenseVector?
Here is roughly what I am doing. I'm guessing using Object is not right for the type. . .
DefaultLeapFrame df = leapFrameSupport.select(frame2, Arrays.asList("feat1", "feat2", "feat3", "probability", "prediction"));
Tensor<Object> tensor = df.dataset().head().getTensor(3);
Thanks
So the MLeap documentation for the Java DSL is not so good but I was able to look over some unit tests (link) that pointed me to the right thing to use. In case anyone else is interested, this is what I did.
DefaultLeapFrame df = leapFrameSupport.select(frame, Arrays.asList("feat1", "feat2", "feat3", "probability", "prediction"));
TensorSupport tensorSupport = new TensorSupport();
List<Double> tensor_vals = tensorSupport.toArray(df.dataset().head().getTensor(3));
I figured that the latest build release would allow me to use ejs globally without using node so I tried doing so.
Though, when I try to use ejs.renderFile(params...), i get the error:
TypeError: exports.fileLoader is not a function
Which is just another node module. Is there a way to get around this?
Note: This is the only time we use EJS at my company, so, if not, would you kindly point me in a good direction in how to render .ejs files.
Update: You can create an EJS object by running
new EJS({url: some/url/to/file.ejs}).render({dataToPass: data, moreData: secondData});
yet another way you can use render instead of renderFile, and your ejs file can be get as string:
// here using jQuery
$.get(you_ejs_file_path).then(function (str, status, xhr) {
const html = ejs.render(str, your_data)); // str is ejs file
});
I'm trying to make a program that checks avaliable positions and books the first avaliable one. I started writing it and i ran into a problem pretty early.
The problem is that when I try to connect with the site (which is https) the program doesn't do anything. It doesn't throw an error, it doesn't crash. And the weirdest thing is that it works with some https websites and with some it doesn't.
I've spent countless hours trying to resolve this problem. I tried using htmlunitdriver and it still doesn't work. Please help.
private final WebClient webc = new WebClient(BrowserVersion.CHROME);
webc.getCookieManager().setCookiesEnabled(true);
HtmlPage loginpage = webc.getPage(loginurl);
System.out.println(loginpage.getTitleText());
I'm getting really frustrated with this. Thank you in advance.
As far as i can see this has nothing to do with HttpS. It is a good idea to do some traffic analysis using Charles or Fiddler.
What you can see....
The page returned from the server as response to your first call to https://online.enel.pl/ loads some external javascript. And then the story begins:
This JS looks like
(function() {
var z = "";
var b = "766172205f3078666.....";
eval((function() {
for (var i = 0; i < b.length; i += 2) {
z += String.fromCharCode(parseInt(b.substring(i, i + 2), 16));
}
return z;
})());
})();
As you can see someone likes to hide the real javascript that gets processed.
Next step is to check the javascript after this simple decoding
It is really huge and looks like this
var _0xfbfd = ['\x77\x71\x30\x6b\x77 ....
(function (_0x2ea96d, _0x460da4) {
var _0x1da805 = function (_0x55e996) {
while (--_0x55e996) {
_0x2ea96d['\x70\x75\x73\x68'](_0x2ea96d['\x73\x68\x69\x66\x74']());
}
};
.....
Ok now we have obfuscated javascript. If you like you can start with http://ddecode.com/hexdecoder/ to get some more readable text but this was the step where i have stopped my analysis. Looks like this script does some really bad things or someone still believes in security by obscurity.
If you run this with HtmlUnit, this codes gets interpreted - yes the decoding works and the code runs. Sadly this code runs endless (maybe because of an error or some incompatibility with real browsers).
If you like to get this working, you have to figure out, where the error is and open an bug report for HtmlUnit. For this you can simply start with a small local HtmlFile and include the code from the first external javascript. Then add some log statements to get the decoded version. Then replace this with the decoded version and try to understand what is going on. You can start adding alert statements and check if the code in HtmlUnit follows the same path as browsers do. Sorry but my time is to limited to do all this work but i really like to help/fix if you can point to a specific function in HtmlUnit that works different from real browsers.
Without the URL that you are querying it is dificult to say what could be wrong. However, having worked with HTML unit some time back I found that it was failing with many sites that I needed to get data from. The site owners will do many things to avoid you using programs to access them and you might have to resort to using some lower level library like Apache HTTP components where you have more control over what is going on under the hood.
Also check if the website is constructed using JavaScript which is getting more and more popular but making it increasingly dificult to use programs to interrogate the content.
There are some samples on http://www.mybatis.org/mybatis-dynamic-sql/docs/select.html.
I want to implement limit/offset for mysql but failed to see any document on describing how to extend this library to support additional where condition.
here is what i'd like to achieve:
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
.from(animalData)
.where(id, isIn(1, 5, 7))
.and(bodyWeight, isBetween(1.0).and(3.0))
.orderBy(id.descending(), bodyWeight)
.limit(1).offset(10)
.build()
.render(RenderingStrategy.MYBATIS3);
There are a couple of resources you can use.
This page - http://www.mybatis.org/mybatis-dynamic-sql/docs/whereClauses.html - shows an example of using standalone where clauses to build a paging query. This is not exactly what you are looking for, but it shows one way to do it.
There is a unit test showing something that is closer to what you are looking for here - https://github.com/mybatis/mybatis-dynamic-sql/tree/master/src/test/java/examples/paging. This code works for MySQL and you could use it as is.
I hope to make this a little easier in a future release.
Is there a way to call solrs analysis api in java using solr-core and get the analyzed tokens.
Analysis api takes fieldName or fieldType and values and give the analyzed tokens.
Is there a way to get those tokens from java?
I found the following link: FieldAnalysisRequestHandler, But I could not get any examples to use it.
In the Admin UI (for which the FieldAnalysisRequestHandler is meant) you can call it by selecting a core and then go to the "Analysis" entry.
See https://cwiki.apache.org/confluence/x/UYDxAQ or https://cwiki.apache.org/confluence/x/FoDxAQ for that.
From a client (which I guess you mean, as you tagged this question with solrj) you need to call the correct URL.
Typically the FieldAnalysisRequestHandler is bound to /analysis/field, see your solrconfig.xml.
From Solrj it should work like this:
SolrQuery query = new SolrQuery();
solrQuery.setRequestHandler("/analysis/field");
solrQuery.set("analysis.fieldtype", "mytype");
solrQuery.set("analysis.fieldvalue", "myval");
QueryResponse solrResponse = solrServer.query(solrQuery);
But it doesn't seem like there's a great support for this in Solrj, probably because it's meant to be called from the Solr Admin UI as mentioned.