R data.table返回没有结果

时间:2017-03-07 19:15:02

标签: sql-server r data.table

这符合我的预期,并返回5行。

public class SelectTimeFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {

private String time = "";
public SelectTimeFragment() {
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current time as the default values for the picker

    final Calendar calendar = Calendar.getInstance();
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);

    // Create a new instance of TimePickerDialog and return it
    return new TimePickerDialog(getActivity(), this, hour, minute,
            DateFormat.is24HourFormat(getActivity()));
}

@Override
public void onTimeSet(TimePicker view, int hour, int minute) {
    time = String.valueOf(hour) + ":" + String.valueOf(minute);

}

public String getTime() {
    return time;
}

这会返回错误。

  

Msg 11536,Level 16,State 1,Line 3
  EXECUTE语句失败,因为其WITH RESULT SETS子句指定了1个结果集,但该语句仅在运行时发送了0个结果集。

EXECUTE sp_execute_external_script    
  @language = N'R'    
 ,@script = N' OutputDataSet <- InputDataSet;'    
 ,@input_data_1 = N' select top 5 DataField, FilterField from Table1
     where DataField is not null;'    
  WITH RESULT SETS ((DataField float NULL, FilterField char(75) NULL));

我能为数据表找到的所有示例都使用了这种语法,并且显然希望它能够正常工作。 EXECUTE sp_execute_external_script @language = N'R' ,@input_data_1 = N' select top 5 DataField from Table1' ,@script = N' library(data.table) dtf <- data.frame(InputDataSet) dt <- data.table(dtf) dt[,DataField,by=FilterField]' WITH RESULT SETS ((DataField float NULL));

例如,https://www.r-bloggers.com/intro-to-the-data-table-package/

1 个答案:

答案 0 :(得分:0)

解决方案是

 **OutputDataSet <-** dt[,DataField,by=FilterField]'