Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. INSERT INTO dbo.Plots
  2. EXEC sp_execute_external_script
  3. @language = N'R'
  4. ,@script = N' df <- inputDataSet; #read input data
  5. image_file = tempfile(); #create a temporary file
  6. jpeg(filename = image_file, width=500, height=500); #create a JPEG graphic device
  7. hist(df$Ages); #plot the histogram
  8. dev.off(); #dev.off returns the number and name of the new active device (after the specified device has been shut down). (device = graphical device)
  9. #file() opens a file, in this case the image. rb = read binary
  10. #readBin() reads binary data. what = described the mode of the data. In this case, it''s raw data. n = maximum number of records to read.
  11. #data.frame converts the data to a data frame, which is required as output by SQL Server. The result is written to the OutputDataset variable.
  12. OutputDataset <- data.frame(data=readBin(file(image_file,"rb"),what=raw(),n=1e6));
  13. '
  14. ,@input_data_1 = N'SELECT Ages = DATEDIFF(YEAR,[BirthDate],GETDATE())
  15. FROM [AdventureWorksDW2014].[dbo].[DimCustomer];'
  16. ,@input_data_1_name = N'inputDataSet'
  17. ,@output_data_1_name = N'OutputDataset'
  18.  
  19. INSERT INTO dbo.Plots(plot, name)
  20. VALUES(
  21. (EXEC sp_execute_external_script
  22. @language = N'R'
  23. ,@script = N' df <- inputDataSet; #read input data
  24. image_file = tempfile(); #create a temporary file
  25. jpeg(filename = image_file, width=500, height=500); #create a JPEG graphic device
  26. hist(df$Ages); #plot the histogram
  27. dev.off(); #dev.off returns the number and name of the new active device (after the specified device has been shut down). (device = graphical device)
  28. #file() opens a file, in this case the image. rb = read binary
  29. #readBin() reads binary data. what = described the mode of the data. In this case, it''s raw data. n = maximum number of records to read.
  30. #data.frame converts the data to a data frame, which is required as output by SQL Server. The result is written to the OutputDataset variable.
  31. OutputDataset <- data.frame(data=readBin(file(image_file,"rb"),what=raw(),n=1e6));
  32. '
  33. ,@input_data_1 = N'SELECT Ages = DATEDIFF(YEAR,[BirthDate],GETDATE())
  34. FROM [AdventureWorksDW2014].[dbo].[DimCustomer];'
  35. ,@input_data_1_name = N'inputDataSet'
  36. ,@output_data_1_name = N'OutputDataset')
  37. , 'testname'
  38. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement