Informatica datatype conversion - informatica

wanted to have two columns separate in target table
Column: CTDATE in YYYYMMDD Format
Column: CTTIME in HHMMSS Format.
How can I populate in Expression Transformation? What is the expression used?
Please guys, help me out.
I used
TO_CHAR(in_column, 'YYYYMMDD') for CTDATE
TO_CHAR(in_column, 'HHMISS') for CTTIME

If your in_column type is already date/time then what you are using right now is almost correct, except use HH24MISS instead of HHMISS. Or use HH12MISS AM.
TO_CHAR(in_column, 'YYYYMMDD') for CTDATE
TO_CHAR(in_column, 'HH24MISS') for CTTIME
If in_column is a string, the first convert it to a date/time. Suppose in_column is coming as 'Jan 24 2017 14:24:56' then
first create a variable v_in_column as TO_DATE( in_column, 'MON DD
YYYY HH24:MI:SS' )
Then use this variable to derive CTDATE and
CTTIME
TO_CHAR(v_in_column, 'YYYYMMDD') for CTDATE
TO_CHAR(v_in_column, 'HHMISS') for CTTIME

Related

Finding time and date with Regular Expression (RegEx) in Dart language

I'm writing an application with Flutter. I read the times and dates from a source. The date and time format string sent by the resource is:
(Day, Month, Year, Hour, Minute, Second)
07.04.2021 13:30:00
03.04.2021 11:30:00
04.04.2021 17:30:00
03.04.2021 17:30:00
I want to convert this date and time format to DateTime data type with DateTime.parse() function. Here are some examples of what this function accepts as strings and what I need:
"2012-02-27 13:27:00"
"20120227 13:27:00"
"20120227T132700"
I have to convert the string type data coming to me from the source into one of these formats. But in Dart language I couldn't create the Regular Expression needed to do this and couldn't find it anywhere.
I would be very grateful if anyeone could help me understand what I should do.
If you have to play a lot with the dates, you could use the Jiffy package to ease your development.
DateTime yourDatetime = Jiffy("07.04.2021 13:30:00", "dd.MM.yyyy hh:mm:ss").dateTime;
This is a piece a cake by using regular expressions:
var regExp = RegExp(r'(\d{4}-?\d\d-?\d\d(\s|T)\d\d:?\d\d:?\d\d)');
use DateFormat.parse and DateFormat.format from intl package:
https://api.flutter.dev/flutter/intl/DateFormat/parse.html
https://api.flutter.dev/flutter/intl/DateFormat/format.html
final date = DateFormat("yyyy.MM.dd HH:mm:ss").parse("07.04.2021 13:30:00");
DateFormat("yyyy-MM-dd HH:mm:ss").format(date);
DateTime.parse accepts only a subset of ISO 8601 formats: https://api.flutter.dev/flutter/dart-core/DateTime/parse.html

How to read and output numeric values properly in BigQuery?

I'm trying to read the following rows out of a CSV file stored in GCS
headers: "A","B","C","D"
row1:"4000,0000000000000","15400000,000","12311918,400000","3088081,600"
row2:"5000,0000000000000","19250000,000","15389898,000000","3860102,000"
The issue here is how BigQuery is actually interpreting and thus outputting these numbers:
Results query number 1
It's interpreting A as FLOAT64, and B, C and D as INT64, which is okay since I decided to use autodetect schema. But when I try to convert it to a different type it's still outputting the numbers unproperly.
This is the query:
SELECT
CAST(quantity AS INT64) AS A,
CAST(expenses_2 AS FLOAT64) AS B,
CAST(cexpenses_3AS FLOAT64) AS C,
CAST(expenses_4 AS FLOAT64) AS D
FROM
`wide-gecko-289100.bqtest.expenses`
These are the results of query above:
Result query number 2
Either way, it's misinterpreting how to read the numbers, it should be as follows:
row1: [4000] [15400000] [12311918,4] [3088081,6]
row2: [5000] [19250000] [15389898] [3860102]
Is there a way to solve this?
This is due to BigQuery not understanding the localized format you're using for the numeric values. It expects the period (.) character for the decimal separator.
If you can't deal with this early in the process that produces the CSV files in BigQuery, another strategy is to instead use a string type for the columns, and then do some manipulation.
Here's a simple conversion example that shows some string manipulation and casting to get to the desired type. If you're using both commas and periods as part of the localized format, you'll need a more complex string manipulation.
WITH
sample_row AS (
SELECT "4000,0000000000000" as A, "15400000,000" as B,"12311918,400000" as C,"3088081,600" as D
)
SELECT
A,
CAST(REPLACE(A,",",".") AS FLOAT64) as A_as_float64,
CAST(CAST(REPLACE(A,",",".") AS FLOAT64) AS INT64) as A_as_int64
FROM
sample_row
You could also generalize this as a user defined function (temporary or persisted) to make it easier to reuse:
CREATE TEMPORARY FUNCTION parseAsFloat(instr STRING) AS (CAST(REPLACE(instr,",",".") AS FLOAT64));
WITH
sample_row AS (
SELECT "4000,0000000000000" as A, "15400000,000" as B,"12311918,400000" as C,"3088081,600" as D
)
SELECT
CAST(parseAsFloat(A) AS INT64) as A,
parseAsFloat(B) as B,
parseAsFloat(C) as C,
parseAsFloat(D) as D,
FROM
sample_row
I think this is an issue with how BigQuery interprets a comma. It seems to detect it as a thousands separator rather than a decimal.
https://issuetracker.google.com/issues/129992574
Is it possible to replace with a "." instead?

Presto SQL: TO_UNIXTIME

I want to convert a readable timestamp to UNIX time.
For example: I want to convert 2018-08-24 18:42:16 to 1535136136000.
Here is my syntax:
TO_UNIXTIME('2018-08-24 06:42:16') new_year_ut
My error is:
SYNTAX_ERROR: line 1:77: Unexpected parameters (varchar(19)) for function to_unixtime. Expected: to_unixtime(timestamp) , to_unixtime(timestamp with time zone)
You need to wrap the varchar in a CAST to timestamp:
to_unixtime(CAST('2018-08-24 06:42:16' AS timestamp)) -- note: returns a double
If your timestamp value doesn't have fraction of second (or you are not interested in it), you can cast to bigint to have integral result:
CAST(to_unixtime(CAST('2018-08-24 06:42:16' AS timestamp)) AS BIGINT)
If your readable timestamp value is a string in different format than the above, you would need to use date_parse or parse_datetime for the conversion. See https://trino.io/docs/current/functions/datetime.html for more information.
Note: when dealing with timestamp values, please keep in mind that: https://github.com/trinodb/trino/issues/37

How to format this date as a string

Here is my scenario. I am getting this date from a database:
11-AUG-15 10.38.00.000000000 AM
Is there any way to format this string to look something similar to mm/dd/yy?
So far I have tried the following with no luck:
DateFormat()
CreateODBCDate()
LSParseDateTime()
Every time I use one of the above, I get the following error:
11-AUG-15 10.38.00.000000000 AM is an invalid date or time string.
Any advise will be greatly appreciated.
Thanks!
parseDateTime("11-AUG-15 10.38.00.000000000 AM", "dd-MMM-yy hh.mm.ss.S aa");
Run me: http://trycf.com/gist/aac6d63777ae1b0e9aa3/acf?theme=monokai
Then you are free to use DateFormat() or DateTimeFormat()to format the date object.

C++ boost date format

I have a vector string of dates in the from "dd-mmm-yyyy" so for example
todays date would be:
std::string today("07-Sep-2010");
I'd like to use the date class in boost but to create a date object the
constructor for date needs to be called as follows:
date test(2010,Sep,07);
Is there any easy/elegant way of passing dates in the format "dd-mmm-yyyy"?
My first thought was to use substr and then cast it? But I've read that there's also
the possibility of using 'date facets'?
Thanks!
include "boost/date_time/gregorian/parsers.hpp"
date test = boost::gregorian::from_us_string("07-Sep-2010")
There is a builtin parser for this form of date in Boost itself, check out the docs here:
http://www.boost.org/doc/libs/1_44_0/doc/html/date_time/date_time_io.html#date_time.io_objects
date_type parse_date(...)
Parameters:
string_type input
string_type format
special_values_parser
Parse a date from the given input using the given format.
string inp("2005-Apr-15");
string format("%Y-%b-%d");
date d;
d = parser.parse_date(inp,
format,
svp);
// d == 2005-Apr-15
with inp adjusted for your needs.