简体   繁体   English

java.lang.String对象[]的数据类型与值meta [Date]不对应

[英]The data type of java.lang.String object [] does not correspond to value meta [Date]

Using Pentaho with Python Plugin, I have an incoming CSV which has two fields, Month and Year , that I need to create a Date out of. 将Pentaho与Python插件配合使用时,我有一个传入的CSV,其中包含两个字段MonthYear ,我需要根据这些字段创建Date Month contains full month names, eg, "January", "February", etc. Month包含完整的月名称,例如“一月”,“二月”等。

To do this, I create pandas script ("create date"), then add Day field and set to 1, then get the month numbers from Month , then create date_tw field and create the datetime from Year , Month , Day . 为此,我创建了pandas脚本(“创建日期”),然后添加Day字段并将其设置为1,然后从Month获取月份号,然后创建date_tw字段并从YearMonthDay创建日期时间。

create date outputs all fields, and the new date_tw field as Date type. create date输出所有字段,并将新的date_tw字段作为Date类型。

在此处输入图片说明

One of the field outputs from python script: python脚本的字段输出之一:

在此处输入图片说明

Data Output creates a table and date_tw is of Date type. Data Output创建一个表,并且date_twDate类型。


So far we have: newly created date_tw from python, which is fed to Data Output , which has already created the table with date_tw also as Date type. 到目前为止,我们已经:从python重新创建了date_tw ,它被馈送到Data Output ,后者已经使用date_tw作为Date类型创建了表。 Both are Date types. 两者都是Date类型。

Yet I get this error: 但是我得到这个错误:

date_tw Date : There was a data type error: the data type of java.lang.String object [06/01/2017] does not correspond to value meta [Date] date_tw日期:数据类型错误:java.lang.String对象[06/01/2017]的数据类型与值meta [Date]不对应

It looks like I should turn off "Lazy Conversion" at the CSV file input step. 看来我应该在CSV文件输入步骤中关闭“惰性转换” This was also done. 这也完成了。

Pandas script in Pentaho: Pentaho中的Pandas脚本:

import pandas as pd
import calendar as cal

df['Day'] = 1
mapping = {v : k for k, v in enumerate(cal.month_name)}
df['Month'] = df['Month'].map(mapping) 
df['date_tw'] = ''
df['date_tw'] = pd.to_datetime(df[['Year', 'Month', 'Day']], format='%Y/%m/%d')
df['date_tw'] = df['date_tw'].dt.strftime('%m/%d/%Y')

result_df = df

Postgresql table field: PostgreSQL表字段:

在此处输入图片说明

Data types match and lazy conversion is off. 数据类型匹配并且延迟转换已关闭。 What am I missing? 我想念什么?

Pentaho metadata contains the date format for each object of type Date. Pentaho元数据包含日期类型的每个对象的日期格式。 And the date_tw of the Python script seams to be in the format dd/mm/yyyy. 并且Python scriptdate_tw的格式为dd / mm / yyyy。

You can check the type and format of any field with a right click on the Python script and select Output fields... . 您可以通过右键单击Python script并选择Output fields...来检查任何字段的类型和格式。 Check if it is dd/mm/yyyy nd not your locale. 检查它是否是dd / mm / yyyy nd而不是您的语言环境。

If it is not and if the Python script does not let you specify the date format, do it with the strftime on the last but one line. 如果不是,并且Python script不允许您指定日期格式,请在最后一行(只有一行)上使用strftime进行操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spark DF 枢轴错误:方法枢轴([类 java.lang.String,类 java.lang.String])不存在 - Spark DF pivot error: Method pivot([class java.lang.String, class java.lang.String]) does not exist pyspark Py4J 错误使用 canopy :PythonAccumulatorV2([class java.lang.String, class java.lang.Integer, class java.lang.String]) 不存在 - pyspark Py4J error using canopy :PythonAccumulatorV2([class java.lang.String, class java.lang.Integer, class java.lang.String]) does not exist JPype1=0.7.0: TypeError: Unable to convert str ro java type class java.lang.String - JPype1=0.7.0: TypeError: Unable to convert str ro java type class java.lang.String 小鸭,int() 参数必须是一个字符串,一个类似字节的 object 或一个数字,而不是 'java.lang.String', - Duckling, int() argument must be a string, a bytes-like object or a number, not 'java.lang.String', 将 java.lang.string 转换为 PYthon 字符串/字典 - Converting java.lang.string to PYthon string/dictionary 使用Spark SQL时无法将B强制转换为java.lang.String - Getting B cannot be cast to java.lang.String when using Spark SQL elasticsearch 映射预期的 map 用于字段 [name] 上的属性 [fields],但得到了 class Z93F725A07423FE21C846Zlang4。 - elasticsearch mapping Expected map for property [fields] on field [name] but got a class java.lang.String 数据框检查条件是否与对应的值匹配 - data frame check if the condition is matching with correspond value 如何确定Excel单元格的值类型(数据类型,如日期,字符串,浮点数等) - How to determine the excel cell value type(data type such as date, string, float etc.) 为什么 11 的值对应于此灰度图像中的白色(matplotlib) - Why does the value of 11 correspond to white in this grayscale image(matplotlib)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM