0

我正在尝试使用 spark SQL 从 MySQL 表中获取一些记录我在执行该查询时遇到错误

我想根据列的日期获取数据该列的数据类型是 MySQL 中的 DATETIME我正在使用.Net Technology

这是我正在执行的查询

老的:

spark.sqlContext("select count(*), classification_id, to_date(cast('total_start' as date)) from call_stats where campaign_id = 172 and contact_list_id = 6288 and total_start between '2017-07-06 00:00:00' and '2017-07-07 23:59:00' group by to_date(cast('total_start' as date)) , classification_id").Collect();

这里 total_start 是我的表列,类型为 datetime 我想将输出作为 total_start 的日期、total_start 的周、total_start 的月份和 total_start 的年份

例外

方法或操作未实现

更新

将 qyery 更改为后:

select count(*), classification_id, date_format( cast( total_start as date), 'yyyy-MM-dd') from call_stats where campaign_id = 172 and contact_list_id = 6288 and total_start between '2017-07-06 00:00:00' and '2017-07-07 23:59:00' group by date_format( cast( total_start as date), 'yyyy-MM-dd'), classification_id 

得到了新的例外:

匿名托管的 DynamicMethods 程序集:无法将类型“Microsoft.Spark.CSharp.Sql.DataFrame”隐式转换为“System.Collections.IEnumerable”。存在显式转换(您是否缺少演员表?)

任何帮助将不胜感激

4

1 回答 1

0

我正在使用一种存在但不正确的方法,所以我只需要更改该查询,例如:

select count(*) as count, classification_id, date_format( cast(total_start as date), 'dd-MM-yyyy')as label from call_stats where campaign_id = 172 and contact_list_id = 6288 and total_start between '2017-07-06 00:00:00' and '2017-07-14 23:59:00' group by date_format( cast(total_start as date), 'dd-MM-yyyy') ,classification_id

对于周、月和年也是如此,我得到了年查询示例的答案:

select count(*) as count, classification_id, year(total_start) as label from call_stats where campaign_id = 172 and contact_list_id = 6288 and total_start between '2015-08-01 00:00:00' and '2017-09-22 23:59:00' group by year(total_start) , classification_id

对于月份的查询示例是:

select count(*) as count, classification_id, month(total_start) as label from call_stats where campaign_id = 77 and contact_list_id = 6037 and total_start between '2017-04-06 00:00:00' and '2017-05-26 23:59:00' group by month(total_start) , classification_id

对于周查询示例:

select count(*) as count, classification_id, weekofyear(total_start) as label from call_stats where campaign_id = 172 and contact_list_id = 6288 and total_start between '2017-07-06 00:00:00' and '2017-07-14 23:59:00' group by weekofyear(total_start) , classification_id
于 2017-10-13T04:53:42.770 回答