Mobius:Spark Sql:无法将类型'Microsoft.Spark.CSharp.Sql.DataFrame'隐式转换为'System.Collections.IEnumerable'

时间:2017-09-22 05:20:25

标签: apache-spark apache-spark-sql mobius

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

我想根据列的日期获取数据列的数据类型是MySQL中的DATETIME 我正在使用.Net技术工作

这是我正在执行的查询

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”。存在显式转换(您是否缺少演员?)

任何帮助将不胜感激

1 个答案:

答案 0 :(得分: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