检查Hbase表是否存在的最快方法是什么?看看这个api:
http://hbase.apache.org/devapidocs/org/apache/hadoop/hbase/client/HBaseAdmin.html以下 哪项是最快的:
使用#4,您将获得所有表的列表并通过它进行迭代,并比较其中一个表是否与您的表名匹配.
还是有另一种更聪明的方式?
请参阅http://docs.oracle.com/javase/7/docs/api/java/util/Random.html#setSeed(long)。代码将乘数播种,然后将其减少为mod 2 ^ 48。为什么不减少传递的种子mod 2 ^ 48?C等效种子48不执行异或。
我有一个这种结构的xml:
<emails>
<record>
<field name="host"><![CDATA[yahoo]]></field>
<field name="user"><![CDATA[abc]]></field>
</record>
<record>
<field name="host"><![CDATA[gmail]]></field>
<field name="user"><![CDATA[abc]]></field>
</record>
<record>
<field name="host"><![CDATA[yahoo]]></field>
<field name="user"><![CDATA[cdx]]></field>
</record>
</emails>
Run Code Online (Sandbox Code Playgroud)
并且,我想计算host = yahoo的记录数.我知道我需要使用count(),但我无法弄清楚如何.
我目前在控制器助手模块中有以下代码.它允许我通过抓住conn的引用来重定向回到上一页.这样做的问题是,如果表单上的输入无效,例如,conn的referrer将重置为当前页面.
def redirect_back(conn, alternative \\ "/") do
path = conn
|> get_req_header("referer")
|> referrer
path || alternative
end
defp referrer([]), do: nil
defp referrer([h|_]), do: h
Run Code Online (Sandbox Code Playgroud)
如何将引用者保存到正确的上一页,以便即使出现类似无效输入的内容,也可以使用它进行重定向?
每次访问https://team_abc.dev.myapp.me/时都会出现以下错误
This issue might be specific for subdomains. Not very sure in what other contexts this issue arrises.
07:26:06.498 [error] Could not check origin for Phoenix.Socket transport.
This happens when you are attempting a socket connection to
a different host than the one configured in your config/
files. For example, in development the host is configured
to "localhost" but you may be trying to access it from
"127.0.0.1". To fix this issue, you may either:
1. update [url: …Run Code Online (Sandbox Code Playgroud) 我正在使用 Phoenix 1.3.0-rc,我想使用 .json 在我的 json 返回中打印 url user_path(...)。
我的控制器:
...
def show(conn, %{"id" => id}) do
user = User.find(id)
render(conn, "show.json", user: user)
end
...
Run Code Online (Sandbox Code Playgroud)
我的看法:
...
def render("show.json", %{user: user}) do
%{
data: render_one(user, __MODULE__, "user.json"),
links: render_one(user, __MODULE__, "links.json")
}
end
...
def render("links.json", %{user: user}) do
%{
self: "/api/v1/users/#{user.id}"
}
end
...
Run Code Online (Sandbox Code Playgroud)
我想这样写:
self: user_path(conn, :show, user.id)
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:undefined function conn/0
在我将许多文件上传到 S3 时,使用 Task.async_stream 效果很好。
\n\n尝试在 download_many 函数中使用它,该函数采用 url 和 id 的关键字列表。当我在 iex 会话中运行 download_many 函数时,它返回以下输出:
\n\niex(1)> Karma.S3.download_many(1)\n #Function<1.112846234/2 in Task.build_stream/3>\n #Function<1.112846234/2 in Task.build_stream/3>\nRun Code Online (Sandbox Code Playgroud)\n\n这是函数:
\n\ndef download_many(_urls) do\n urls = [\n \xe2\x80\x9c5\xe2\x80\x9d: \xe2\x80\x9chttps://engine-image-uploads.s3.amazonaws.com/engine-image-uploads/d4a9f8adb58b4e0b83c47e8f3b21d421-fillable.pdf\xe2\x80\x9c,\n \xe2\x80\x9c3\xe2\x80\x9d: \xe2\x80\x9chttps://engine-image-uploads.s3.amazonaws.com/engine-image-uploads/ccd6d66cb4304b369a025efe3b26e68b-fillable.pdf\xe2\x80\x9d\n ]\n\n ops = [max_concurrency: System.schedulers_online() * 3, timeout: 20000]\n\n tasks = Task.async_stream(urls, &download_with_id/1, ops)\n |> Enum.to_list()\n IO.inspect tasks\n end\n\n def download_with_id({id, url}) do\n file_destination = System.cwd() <> \xe2\x80\x9c/tmp/altered_document_\xe2\x80\x9d <> Atom.to_string(id) <> \xe2\x80\x9c.pdf\xe2\x80\x9d\n download(url, file_destination)\n |> Tuple.insert_at(2, id)\n end\nRun Code Online (Sandbox Code Playgroud)\n\n以及该文件的链接:https://github.com/karmaradio/karma/blob/async-download_many/lib/S3.ex#L58 …
我正在 Phoenix 应用程序中的三个表上运行搜索功能,并且我想使用 SQL 的 UNION 运算符之类的东西来连接它们。
我有三张桌子:
mix phx.gen.json Accounts User users handle:string email:string
mix phx.gen.json Content Post posts title:string content:string
mix phx.gen.json Content Category categories name:string
Run Code Online (Sandbox Code Playgroud)
我们假设没有外键或链接表。
如果我想在 SQL 中对这些进行搜索,我会这样做:
SELECT handle FROM users WHERE handle LIKE "%string%"
UNION
SELECT title FROM posts WHERE title LIKE "%string%"
UNION
SELECT name FROM categories WHERE name LIKE "%string%"
Run Code Online (Sandbox Code Playgroud)
然而,Ecto 2 似乎不支持联合。我想做这样的事情:
query1 =
from u in User,
where: ilike(u.handle, ^"%#{str}%"),
select: u
query2 =
from p in Post,
where: ilike(p.title, …Run Code Online (Sandbox Code Playgroud) 我正在按照本教程进行操作,在添加此代码和角色Factory之后,我收到以下错误:
15:09:08.808 [错误] GenServer #PID <0.245.0>终止**(UndefinedFunctionError)函数Ecto.Adapters.SQL.begin_test_transaction/1未定义或私有.你是说其中一个:
Run Code Online (Sandbox Code Playgroud)* in_transaction?/1 (ecto) Ecto.Adapters.SQL.begin_test_transaction(Pxblog.Repo) (elixir) src/elixir_compiler.erl:125: :elixir_compiler.dispatch_loaded/6 (elixir) src/elixir_lexical.erl:17: :elixir_lexical.run/3 (elixir) src/elixir_compiler.erl:30: :elixir_compiler.quoted/3 (elixir) lib/code.ex:363: Code.require_file/2 (elixir) lib/enum.ex:651: Enum."-each/2-lists^foreach/1-0-"/2 (elixir) lib/enum.ex:651: Enum.each/2 (mix) lib/mix/tasks/test.ex:216: Mix.Tasks.Test.run/1
这是我的test_helper.exs文件:
{:ok, _} = Application.ensure_all_started(:ex_machina)
ExUnit.start
Mix.Task.run "ecto.create", ~w(-r Pxblog.Repo --quiet)
Mix.Task.run "ecto.migrate", ~w(-r Pxblog.Repo --quiet)
Ecto.Adapters.SQL.begin_test_transaction(Pxblog.Repo)
Run Code Online (Sandbox Code Playgroud)
可能有什么不对?我已经更新了所有的依赖项mix deps.update --all.
提前致谢!
在我的 phoenix 项目中,我有一个通过连接表链接的帖子和标签架构
schema "posts" do
field :title, :string
field :body, :string
many_to_many :tags, App.Tag, join_through: App.PostsTags , on_replace: :delete
timestamps()
end?
Run Code Online (Sandbox Code Playgroud)
我如何确保使用 put_assoc 存在标签?
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:title, :body])
|> put_assoc(:tags, parse_tags(params), required: true)
|> validate_required([:title, :body, :tags])
end
Run Code Online (Sandbox Code Playgroud)
put_assoc 上的 required: true 和添加 :tags 来验证 required 都不像我想象的那样工作。