我正在从贝叶斯统计模型中抽取样本,使用Avro将其序列化,然后将其上传到S3,然后使用Athena进行查询。
我需要帮助编写一个取消嵌套表中数组的查询。
CREATE TABLE查询看起来像:
CREATE EXTERNAL TABLE `model_posterior`(
`job_id` bigint,
`model_id` bigint,
`parents` array<struct<`feature_name`:string,`feature_value`:bigint, `is_zid`:boolean>>,
`posterior_samples` struct <`parameter`:string,`is_scaled`:boolean,`samples`:array<double>>)
Run Code Online (Sandbox Code Playgroud)
“ posterior_samples”列中的“ samples”数组是存储样本的位置。我设法通过以下查询取消嵌套“ posterior_samples”结构:
WITH samples AS (
SELECT model_id, parents, sample, sample_index
FROM posterior_db.model_posterior
CROSS JOIN UNNEST(posterior_samples.samples) WITH ORDINALITY AS t (sample, sample_index)
WHERE job_id = 111000020709
)
SELECT * FROM samples
Run Code Online (Sandbox Code Playgroud)
现在,我想要的是取消嵌套父母栏。此列中的每个记录都是一个结构数组。我试图创建一个仅包含该结构数组中“ feature_value”键的值数组的列。(我之所以想要一个数组,是因为parents数组的长度可以> 1)。
换句话说,对于父行中的每个数组,我想要一个大小相同的数组。该数组应仅包含原始数组中结构的“ feature_value”键的值。
关于如何解决这个问题的任何建议?
谢谢。
我想从用户那里收集HTML5录音并将它们存储在S3中.我正在使用javasscript资源进行浏览器内的音频和视频录制,使用名为MediaStreamRecorder.js的 WebRTC 来收集录音.我添加了Carrierwave和Fog,并验证我可以成功将音频文件上传到S3.我还成功地使用MediaStreamRecorder.js来收集音频Blob并在音频标签中播放.我最初的想法是直接添加blob URL作为隐藏表单输入的值,并通过表单提交将音频提供给控制器和Carrierwave,就像使用"remote_file_url"提交链接到远程文件而不是上传本地文件.
那失败了.显然,blob URL无法以这种方式处理.
我发现这篇博客文章解释了我如何通过Javascript直接向Carrierwave提交文件.我试图实现这个但失败了.我正在使用Chrome.
我有一个名为"Recording"的上传器:
class RecordingUploader < CarrierWave::Uploader::Base
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
Run Code Online (Sandbox Code Playgroud)
我有一个模型"背诵":
class Recitation < ActiveRecord::Base
belongs_to :lesson
mount_uploader :recording, RecordingUploader
end
Run Code Online (Sandbox Code Playgroud)
路线反映Recitation嵌套在名为Lesson的模型中:
resources :lessons do
resources :parts
resources :recitations
end
Run Code Online (Sandbox Code Playgroud)
我在Recitation控制器中的new和create方法:
def new
@lesson = Lesson.find(params[:lesson_id])
@recitation = Recitation.new
end
def create
@lesson = Lesson.find(params[:lesson_id])
@recitation = @lesson.recitations.new(recitation_params)
if @recitation.save
redirect_to thanks_path
else
flash[:error] = "There was a problem saving your recording."
render :new
end
end
Run Code Online (Sandbox Code Playgroud)
最后我尝试通过AJAX将blob传递给控制器.
function onMediaSuccess(stream) { …Run Code Online (Sandbox Code Playgroud) 我正在为 API 编写一些 rspec,并尝试直接在 Rails 控制台中测试 HTTP 请求代码,以便我可以看到返回的结果。
例如,我的规范中有以下几行
json_data = '{"user": {"email": "#{user.email}", "password": "#{user.password}"}}'
post "api/v1/users/sign_in", json_data
@token = json(last_response)[:client][:auth_token]
get 'api/v1/users', {}, {'Authorization' => @token}
Run Code Online (Sandbox Code Playgroud)
此代码不起作用,因为我的“json()”函数未正确解析响应。我想使用 JSON 参数获取这些“post”和“get”,并使用 Net::HTTP 在 Rails 控制台中测试它们,这样我就可以看到返回的响应并调试我的规范代码。有人知道该怎么做吗?
如果重要的话,我尝试使用的授权令牌是由 Devise 生成的。