我在找工作NullPointerException
时得到的MapReduce
.它被抛出SerializationFactory
的getSerializer()
方法.我使用的是定制的InputSplit
,InputFormat
,RecordReader
和MapReduce
值类.
我知道错误是在我的InputFormat
类创建拆分后的某个时间抛出的,但是在创建之前RecordReader
.据我所知,它是在"清理暂存区"消息后直接发生的.
通过在堆栈跟踪指示的位置检查Hadoop源,看起来getSerialization()
接收空Class<T>
指针时发生错误.JobClient writeNewSplits()
调用这样的方法:
Serializer<T> serializer = factory.getSerializer((Class<T>) split.getClass());
Run Code Online (Sandbox Code Playgroud)
因此,我假设getClass()
在我的自定义InputSplit
对象上调用它时,它返回一个null
指针,但这只是令人困惑.有任何想法吗?
错误的完整堆栈跟踪如下:
12/06/24 14:26:49 INFO mapred.JobClient: Cleaning up the staging area hdfs://localhost:54310/tmp/hadoop-s3cur3/mapred/staging/s3cur3/.staging/job_201206240915_0035 Exception in thread "main" java.lang.NullPointerException at org.apache.hadoop.io.serializer.SerializationFactory.getSerializer(SerializationFactory.java:73) at org.apache.hadoop.mapreduce.split.JobSplitWriter.writeNewSplits(JobSplitWriter.java:123) at org.apache.hadoop.mapreduce.split.JobSplitWriter.createSplitFiles(JobSplitWriter.java:74) at org.apache.hadoop.mapred.JobClient.writeNewSplits(JobClient.java:968) at org.apache.hadoop.mapred.JobClient.writeSplits(JobClient.java:979) at org.apache.hadoop.mapred.JobClient.access$600(JobClient.java:174) at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:897) at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:850) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:396) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121) …
在最近的一个项目中,我遇到了一个错误,我意外地将一个浮点数赋给了一个字符串引用(而不是将float转换为字符串,然后分配它).
代码看起来像这样(在Xcode/Apple LLVM 7.1和GCC 4.9.2下测试):
#include <iostream>
using namespace std;
static void get_text(string &s) {
s = 1.0f; // Legal (not even a warning!)
}
// This version gives a compiler error (as I'd expect)
// static void get_text(string &s) {
// string out = 1.0f;
// s = out;
// }
int main() {
string s;
get_text(s);
cout << s << endl; // Prints garbage
return 0;
}
Run Code Online (Sandbox Code Playgroud)
打印字符串显然会导致垃圾,但我不清楚为什么这不会给出警告.(我最好的猜测是编译器做了某种隐式重新解释转换,从float,int到内存地址......?)
是否有一个警告我可以启用(在Xcode中,理想情况下)将来会阻止这种事情?
我正在研究Ionic电子商务应用程序并使用Laravel中的API.我已经在购物车中添加了产品,但是当我增加购物车中的产品数量时,产品的价格却在增加,但总价格没有更新,而且当从购物车中取出产品时,它也没有更新价格.
这是我的cart.html:
<ion-header>
<ion-navbar color="primary">
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>
Your Cart
</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list *ngFor="let itm of cartItems" class="myitem11">
<ion-item>
<ion-thumbnail item-start >
<img src="{{itm.image}}">
</ion-thumbnail>
<h2>{{itm.name}}</h2>
<p>Actual Price:
<span [ngStyle]="itm?.discountp === '0' ? {'text-decoration':'none'} : {'text-decoration':'line-through'}">
?{{itm.disprice * itm.count}}
</span>
</p>
<p>Discount: {{itm?.discountp}}%</p>
<ion-row class="item-count">
<ion-col class="qty">
<button (click)="decreaseProductCount(itm)" clear ion-button small color="dark" class="mewbtn11">
-
</button>
<button ion-button small clear color="dark" class="mewbtn11">
{{itm?.count}}
</button>
<button (click)="incrementProductCount(itm)" clear ion-button small color="dark" …
Run Code Online (Sandbox Code Playgroud) 假设您有一个 OTP 进程,您希望同步等待其完成(其中“完成”可能是正常退出或崩溃、停止等)。
\n进一步假设,出于业务原因,您不能使用Task.async/1
或相关Task
实用程序生成此进程\xe2\x80\x94,它必须是不依赖于Task.await/2
.
有没有比简单地间歇性轮询更好的方法来做到这一点Process.alive?/1
?我觉得这种事情可能有一个既定的模式,但我一生都找不到它。
def await(pid, timeout) when timeout <= 0 do\n if Process.alive?(pid) do\n Process.exit(pid, :kill) # (or however you want to handle timeouts)\n end\nend\n\n@await_sleep_ms 500\ndef await(pid, timeout) do\n # Is there a better way to do this?\n if Process.alive?(pid) do\n :timer.sleep(@await_sleep_ms)\n await(pid, subtract_timeout(timeout, @await_sleep_ms))\n end\nend\n
Run Code Online (Sandbox Code Playgroud)\n 我正在使用Jenkins来构建.ipa但是在编码时会出现错误.为什么archive命令不受支持?
我得到的错误是:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/Validation /Users/Shared/Jenkins/Home/workspace/ginav-mobile/build/Distribution-iphoneos/ginav-mobile.app
** BUILD SUCCEEDED **
=== BUILD TARGET ginav-mobile OF PROJECT ginav-mobile WITH CONFIGURATION Distribution ===
Check dependencies
unsupported build action 'archive'
Code sign error: No command to generate product wrapper at '/Users/Shared/Jenkins/Home/workspace/ginav-mobile/build/Distribution-iphoneos/ginav-mobile.app'.
** ARCHIVE FAILED **
Run Code Online (Sandbox Code Playgroud) 我的.formatter.exs
项目根目录中有一个 Elixir 项目 文件,如下所示:
[
line_length: 120,
inputs: ["mix.exs", "config/*.exs"],
subdirectories: ["apps/*"]
]
Run Code Online (Sandbox Code Playgroud)
但据我所知,该line_length
参数被忽略了。
给定以下代码,最长的行(长度为 102 个字符)总是被分成两行(when
子句换行):
defmodule SomeModule do
def lookup_data(parameter1, parameter2) when is_integer(parameter1) and is_integer(parameter2) do
:not_implemented
end
end
Run Code Online (Sandbox Code Playgroud)
相比之下,如果我将模块复制并粘贴到在线 Elixir 格式化程序中并将行长度选项设置为 120,则不会对文本进行任何更改(如预期)。
我一定是搞砸了.formatter.exs
,但对于我的生活,我不知道是怎么回事。
我知道,默认情况下,ExUnit.Case 是同步的(根据ExUnit.Case 文档)。我还阅读了这个问题(https://github.com/elixir-lang/elixir/issues/3580),并且案例内的测试函数似乎是串行运行的。
当我运行一个没有全局状态的简单测试用例时,确实是串行运行的。
但是,当我将全局状态与代理一起使用时,执行顺序取决于运气。对于同一个调用
mix test --trace
Run Code Online (Sandbox Code Playgroud)
执行顺序改变。这是我的测试套件:
defmodule SerialTest do
use ExUnit.Case
test "1" do
Agent.update(:card_id, fn nil -> 1 end)
assert true
end
test "2" do
res = Agent.get(:card_id, fn res -> res end)
assert res == 1
end
test "3" do
Agent.update(:card_id, fn id -> 3 end)
assert true
end
test "4" do
res = Agent.get(:card_id, fn res -> res end)
assert res == 3
end
end
Run Code Online (Sandbox Code Playgroud)
有时通过有时不通过。如何使我的函数的执行顺序符合使用代理的全局状态定义它们的文件中的声明顺序?
我只是想从 Programming Elixir 1.0 中运行一个示例 Elixir 程序并得到以下错误,尽管Supervisor 文档使我看起来不应该这样做:
我究竟做错了什么?
我执行iex -S mix并查看错误报告:
Erlang/OTP 18 [erts-7.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
=INFO REPORT==== 2-Apr-2016::20:11:46 ===
application: logger
exited: stopped
type: temporary
** (Mix) Could not start application sequence_supervisor: exited in: SequenceSupervisor.start(:normal, [])
** (EXIT) an exception was raised:
** (MatchError) no match of right hand side value: {:error, {:shutdown, {:failed_to_start_child, Sequence.Server, {:EXIT, {:undef, [{Sequence.Server, :start_link, '{', []}, {:supervisor, :do_start_child, 2, [file: 'supervisor.erl', line: 343]}, {:supervisor, :start_children, …
Run Code Online (Sandbox Code Playgroud) 我有一个行为来抽象解析各种 Phoenix 端点的 URL 查询参数。它看起来像这样:
defmodule Query do
@callback from_query_params(params :: %{optional(String.t()) => any()}) ::
{:ok, parsed :: struct} | {:error, reason :: atom}
end
Run Code Online (Sandbox Code Playgroud)
一个简单的实现如下所示:
defmodule SearchQuery do
@moduledoc "Parses URL query params for search endpoint"
@behaviour Query
@enforce_keys [:search_term]
defstruct @enforce_keys
@typespec t :: %__MODULE__{search_term: String.t()}
@impl Query
def from_query_params(%{"query" => query}) when query != "" do
{:ok, %__MODULE__{search_term: query}}
end
def from_query_params(_), do: {:error, :missing_search_term}
end
Run Code Online (Sandbox Code Playgroud)
在这里我真正想说的是:
t()
)from_query_params/1
应该使用该struct t()
,而不仅仅是任何结构 …