Pentaho - Formatting date in Mondrian - pentaho

I am getting date like 20150910 numeric from backend.
I am creating new level in Dimension (in Mondrian-template)
Is there any way to format the date to 2015-09-10 ?
Can i achieve this using formatString ?
Any pointers will be highly appreciated .
Thanks

You can use a KeyExpression, which accepts SQL statements, then split the string in the various parts and concatenate it back with dashes in between.
See https://mondrian.pentaho.com/documentation/schema.php#XML_KeyExpression
Remark: if you use a KeyExpression you should not use a column attribute.

Related

Data Factory expression substring? Is there a function similar like right?

Please help,
How could I extract 2019-04-02 out of the following string with Azure data flow expression?
ABC_DATASET-2019-04-02T02:10:03.5249248Z.parquet
The first part of the string received as a ChildItem from a GetMetaData activity is dynamically. So in this case it is ABC_DATASET that is dynamic.
Kind regards,
D
There are several ways to approach this problem, and they are really dependent on the format of the string value. Each of these approaches uses Derived Column to either create a new column or replace the existing column's value in the Data Flow.
Static format
If the format is always the same, meaning the length of the sections is always the same, then substring is simplest:
This will parse the string like so:
Useful reminder: substring and array indexes in Data Flow are 1-based.
Dynamic format
If the format of the base string is dynamic, things get a tad trickier. For this answer, I will assume that the basic format of {variabledata}-{timestamp}.parquet is consistent, so we can use the hyphen as a base delineator.
Derived Column has support for local variables, which is really useful when solving problems like this one. Let's start by creating a local variable to convert the string into an array based on the hyphen. This will lead to some other problems later since the string includes multiple hyphens thanks to the timestamp data, but we'll deal with that later. Inside the Derived Column Expression Builder, select "Locals":
On the right side, click "New" to create a local variable. We'll name it and define it using a split expression:
Press "OK" to save the local and go back to the Derived Column. Next, create another local variable for the yyyy portion of the date:
The cool part of this is I am now referencing the local variable array that I created in the previous step. I'll follow this pattern to create a local variable for MM too:
I'll do this one more time for the dd portion, but this time I have to do a bit more to get rid of all the extraneous data at the end of the string. Substring again turns out to be a good solution:
Now that I have the components I need isolated as variables, we just reconstruct them using string interpolation in the Derived Column:
Back in our data preview, we can see the results:
Where else to go from here
If these solutions don't address your problem, then you have to get creative. Here are some other functions that may help:
regexSplit
left
right
dropLeft
dropRight

Teradata handling single digit month and day problem

I have below values coming from a flat file which may contain single digit month & day field:
9/14/2020 07:20:18.630000
7/7/2020 16:24:57.700000
10/24/2019 03:40:52.380000
11/9/2020 20:21:32.420000
Now I need to load this to a column having TIMESTAMP(6) as the data type.
Can someone please help on this? I am using TD SQL Assistant version 16.
SQL Assistant is not a load utility, e.g. TPT fully supports dealing with intput like this.
Your other post shows that you already use a RegEx to add the missing zeroes and you apply the correct format. This is indicating bad data in your input. You might try to spot the error in the input file (check how many rows have been loaded and check the following lines).
Or you apply TRYCAST which doesn't fail, but returns a NULL for bad dates. But yikes, it doesn't support FORMAT, thus you must rearrange the MDY to YMD first:
trycast(RegExp_Replace(RegExp_Replace(x,'\b([0-9])\b', '0\1'), '(..).(..).(....)(.*)','\3-\1-\2\4') as timestamp(6))

Change decimal separator in SSAS from dot to comma

I have a requirement in which I need to display some decimal measures with a comma separator for decimal and not a dot and thousand separators as a dot and not a comma in SSAS. Example 2.245,89
This is a specific requirement for a dutch customer where they used to use this format for reporting purposes.
Any suggestions if this is possible in SSAS? If yes, how can I do this?
Thx!
You can assign the format as described https://dba.stackexchange.com/questions/132786/formatting-a-measure-in-ssas-cube
If you are using a calculated measure, you can use SSAS - How to configure format number for calculated measures?

how do i select certain key/value pair from json field inside a SQL table in SNOWFLAKE

I am currently working on building a dataware house in snowflake for the business that i work for and i have encounter some problems. I used to apply the function Json_value in TSQL for extracting certain key/value pair from json format field inside my original MSSQL DB.
All the other field are in the regular SQL format but there is this one field that i really need that is formated in JSON and i can't seems to exact the key/value pair that i need.
I'm new to SnowSQL and i can't seems to find a way to extract this within a regular query. Does anyone knows a way around my problem ?
* ID /// TYPE /// Name (JSON_FORMAT)/// Amount *
1 5 {En: "lunch, fr: "diner"} 10.00
I would like to extract this line (for exemple) and be able to only retrieve the EN: "lunch" part from my JSON format field.
Thank you !
Almost any time you use JSON in Snowflake, it's advisable to use the VARIANT data type. You can use the parse_json function to convert a string into a variant with JSON.
select
parse_json('{En: "lunch", fr: "diner"}') as VARIANT_COLUMN,
VARIANT_COLUMN:En::string as ENGLISH_WORD;
In this sample, the first column converts your JSON into a variant named VARIANT_COLUMN. The second column uses the variant, extracting the "En" property and casting it to a string data type.
You can define columns as variant and store JSON natively. That's going to improve performance and allow parsing using dot notation in SQL.
For anyone else who also stumbles upon this question:
You can also use JSON_EXTRACT_PATH_TEXT. Here is an example, if you wanted to create a new column called meal.
select json_extract_path_text(Name,'En') as meal from ...

How should date-based queries in Oracle be parameterised

ResultSet rs=st.executeQuery(
"select j.vc_jo_no,
j.dt_jo_date,
p.vc_product_name
from mst_jobcard j,
mst_prod p
where j.vc_product_code=p.vc_product_code
and j.dt_jo_date=to_char("+tdate+","+"'"+dd-mm-yy+"'"+")
");
In my specified query it should display the records based on the date parameter that is being passed in the above query.
the vc_jo_no,dt_jo_date are taken from mst_jobcard table and vc_product_name is taken from mst_prod table.
i have joined the tables.
please help me in how to use the to_char function for date.
when i specify the format i.e dd-mm-yy in the to_char function it gives error.
please help..
If you're going to pass the date as a string Oracle needs it surrounded by single quotes. Also, the "dd-mm-yy" doesn't look right to me. Try this:
ResultSet rs=st.executeQuery(
"select j.vc_jo_no,
j.dt_jo_date,
p.vc_product_name
from mst_jobcard j,
mst_prod p
where j.vc_product_code=p.vc_product_code
and j.dt_jo_date=to_char('"+tdate+"','dd-mm-yy')
");
That said, this method of passing parameters is effectively NOT passing the parameter - it will cause the database to parse a different query for every different date requested, which is likely to cause a scalability issue.
The better approach would be to bind the parameter, using whatever method is provided by ResultSet to bind a variable. You may find you can even bind a date variable natively without having to convert it to a string.
So you're running:
executeQuery("select … where … j.dt_jo_date=to_char("+tdate+","+"'"+dd-mm-yy+"'"+")");
First thing, try put that string in a variable, output it and see if it's in the correct format.
Have you tried:
"… to_char("+tdate+",'dd-mm-yy'")
it seems you're doing unnecessary acrobatics with that string.
And finally, take a look at "Oracle to_char usage" by Burleson Consulting. It was the first link off of Google. Some say Google's a good place to look first.