Formatting the result of oql in VisualVM - visualvm

I have the following oql query running on visualvm against a heap dump and would like the creationTime field formatted as a date time field (its stored as Long).
select { id: s.id.toString(), createdAt: new Date(s.creationTime) }
from org.apache.catalina.session.StandardSession s
The above query lists the following output (snipped)
{
id = 1010827848,
createdAt = sun.org.mozilla.javascript.internal.NativeDate#66106135
}
...
So clearly its been "converted" into a Date but does not display it a human readable format. Doing a toString() on the date object just results in the field being displayed as Invalid Date.
Is it possible to format the the Long field as a Date field?
The id field's value also is off when queried using VisualVM. When I query the same heap dump using Eclipse Analyser I see the right value (which is BE27C51E8BF185A2FB3AA9164EC0C647). What could be happening to that?

The output shows that you are creating JavaScript Date object. The correct part of you OQL should be: createdAt: new java.util.Date(s.creationTime)
There is a known problem with a field, which is named id. See Retrieve "id" field values via VisualVM OQL query for more details. As a workaround you can use s["wrapped-object"].getValueOfField("id") instead of s.id.toString()
With above changes your query should be:
select { id: s["wrapped-object"].getValueOfField("id"),
createdAt: new java.util.Date(s.creationTime).toString() }
from org.apache.catalina.session.StandardSession s

Related

Return inserted id with TypeORM & NestJS raw query: await connection.manager.query(`INSERT INTO

I'm looking to return the id or better yet, all information that was inserted, using a raw query with TypeORM and NestJS. Example as follows:
await connection.manager.query(`INSERT INTO...`)
When assigning the query to a constant and console logging it below, it does not yield any helpful information:
OkPacket {
fieldCount: 0,
affectedRows: 1,
insertId: 0,
serverStatus: 2,
warningCount: 1,
message: '',
protocol41: true,
changedRows: 0
}
As you can see, it returns no pertinent information, the insertId above is obviously incorrect, and it returns this every time, regardless of the actual parameters of the query.
I know with more typical TypeORM queries you can use .return(['name_of_column_you_want_returned']).execute()
and it will return the relevant information just fine. Is there any way to do this with a raw query? Thank you!
tl;dr You're getting the raw mariadb driver response (OkPacket) from the INSERT command, and you'd need a new SELECT query to see the data.
You're using the TypeORM EntityManager, and the docs don't mention a return value. Looking at the source code for query, the return type is any. Since it's a raw query, it probably returns an object based on the type of database you're using rather than having a standard format.
In this case, you're using MariaDb, which returned an OkPacket. Here's the documentation:
https://mariadb.com/kb/en/ok_packet/

splunk search query returns entries with a variable value greater than some number

I've this log entry:
"2014-11-22 02:42:10,545 .. - average:2.74425 , min:1.43 , max:4.007..."
i want to create a search query that returns all log entries with "average > 5"
i want to select the date of the log entry and the average value,
can this be done? how can i do this?
Thanks,
It is quite simple to do in Splunk and you'll have to do it in two steps:
Parse your log to get each of the fields in your log files. To do this use the props.conf and transforms.conf files on your indexer server or on your client if you are using the heavy forwarder. Another option is to send you fields using the key=value format that Splunk knows how to parse by default. Example: "2014-11-22 02:42:10,545 .. - average=2.74425 min=1.43 max=4.007..."
After getting your fields in Splunk just search for average>5 and you'll get all these search results easily.
Answer from splunk:
Did you already extract the average field?
If not, go to Settings -> Fields -> Field Extractions -> New, enter "average" as name, fill in your sourcetype, and use this as inline extraction:
average:(?<average>\d+\.?\d*)
it worked. :)

Getting TypeDoesNotMatch on Timestamp field when inserting using Play Framework with Postgres

I'm trying to insert data into a table called users.
I'm only passing a value for the name field and this exception pops up.
I'm not even passing any Timestamp in the parameter.
The data still gets inserted into the database even if this happens. Why though?
Here is the error I'm getting: [RuntimeException: TypeDoesNotMatch(Cannot convert 2014-10-21 17:41:41.982: class java.sql.Timestamp to Long for column ColumnName(users.joined,Some(joined)))]
Here's the code:
DB.withConnection { implicit conn =>
val id: Option[Long] =
SQL("insert into pinglet.users (name) VALUES ('jel124')")
.executeInsert()
outString += id.getOrElse("nuffin'")
}
Info
joined is a field of data type timestamp with time zone.
My scala version is 2.11.1
java version is 1.8.0_25
My postgres jdbc driver is 9.3-1102-jdbc41
I guess the pk returned by INSERT is a timestamp, and you ask it to be parsed as Option[Long.

Is getting the General ID same as getting FormattedID in rally?

I am trying to get the ID under "General" from a feature item in rally. This is my query:
body = { "find" => {"_ProjectHierarchy" => projectID, "_TypeHierarchy" => "PortfolioItem/Feature"
},
"fields" => ["FormattedID","Name","State","Release","_ItemHierarchy","_TypeHierarchy","Tags"],
"hydrate" => ["_ItemHierarchy","_TypeHierarchy","Tags"],
"fetch"=>true
}
I am not able to get any value for FormattedID, I tried using "_UnformattedID" but it pulls up an entirely different value than the FormattedID. Any help would be appreciated.
LBAPI does not have FormattedID field. You are correct using _UnformattedID. It is the FormattedID without the prefix. For example, this query:
https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/1111/artifact/snapshot/query.js?find={"_ProjectHierarchy":2222,"_TypeHierarchy":"PortfolioItem/Feature","State":"Developing",_ValidFrom: {$gte: "2013-06-01TZ",$lt: "2013-09-01TZ"}},sort:{_ValidFrom:-1}}&fields=["_UnformattedID","Name","State"]&hydrate=["State"]&compress=true&pagesize:200
shows _UnformattedID that correspond to FormattedID as this screenshot shows:
I noticed your are using fields and fetch . Per LBAPI's documentation, it uses fields rather than fetch. If you want to get all fields, use fields=true
As far as the missing custom fields, make sure that the custom field value was set within the dates of the query.
Compare these almost identical queries: the first query does not return a custom field, the second query does.
Query #1:
https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/1111/artifact/snapshot/query.js?find={"_ProjectHierarchy":2222,"_TypeHierarchy":"PortfolioItem/Feature","State":"Developing",_ValidFrom: {$gte: "2013-06-01TZ",$lt: "2013-09-01TZ"}}}&fields=["_UnformattedID","Name","State","c_PiCustomField"]&hydrate=["State","c_PiCustomField"]
Query #2:
https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/11111/artifact/snapshot/query.js?find={"_ProjectHierarchy":2222,"_TypeHierarchy":"PortfolioItem/Feature","State":"Developing",__At: "current"}&fields=["_UnformattedID","Name","State","c_PiCustomField"]&hydrate=["State","c_PiCustomField"]
The first query uses time period: _ValidFrom: {$gte: "2013-06-01TZ",$lt: "2013-09-01TZ"}
The second query uses __At: "current"
Let's say I just create a new custom field on PortfolioItem. It is not possible to create a custom field on PorfolioItem/Feature, so the field is created on PI, but both queries still use "_TypeHierarchy":"PortfolioItem/Feature".
After I created this custom field, called PiCustomField, I set a value of that field for a specific Feature, F4.
The first query does not have a single snapshot that includes that field because that field did not exist in the time period we lookback. We can't change the past.
The second query returns this field for F4. It does not return it for other Features because all other Features do not have this field set.
Here is the screenshot:

How do you query a ravendb index containing dates using Lucene?

I am using the http api to query ravendb (so a LINQ query is not the solution to my question).
My Product document looks like this:
{
"editDate": "2012-08-29T15:00:00.846Z"
}
and I have the index:
from doc in docs.Product
select new { doc.editDate }
I want to query all documents before a certain date AND time. I can query on the DATE using this syntax:
editDate: [NULL TO 2012-09-17]
however I can't figure out how to query the time component as well.
Any ideas?
You can query that using:
editDate: [NULL TO 2012-09-17T15:00:00.846Z]
If you care for a part of that, use:
editDate: [NULL TO 2012-09-17T15:00]
Note that you might have to escape parts of the query, like so:
editDate: [NULL TO 2012\-09\-17T15\:00]
For this to work you also need to ensure that the field is analysed.
In Raven Studio - Add Field -> editDate, and set Indexing to Analyzed.
One way of working around this problem is to store the value not as a date but as the number of seconds since the unix epoch.
This results in a number that you can compare against with ease.
I am using javascript and the moment js library:
{
"editDate": "2012-08-29T15:00:00.846Z",
"editDateUnix": moment("2012-08-29T15:00:00.846Z").unix()
}
Any my index:
from doc in docs.Product
select new { doc.editDate, doc.editDateUnix }
and my lucene query:
"editDate: [NULL TO "+moment("2012-09-17").unix()+"]"