Python的Spark自定义Hadoop配置(PySpark)?(Custom Hadoop Configuration for Spark from Python (PySpark)?)
我有基于
Python
的脚本,应该在Apache Spark
集群上运行。我有
Hadoop
MapReduce
InputFormat
作为RDD
的数据源。 这没问题。问题是我想构建自定义的
Hadoop
Configuration
其中加载了额外的资源文件并设置了属性。 意图是在Python
SparkContext
使用修改后的Configuration
。我可以构建可以构建和加载所需
Hadoop
Configuration
JVM
代码。 如何使用PySpark
将其附加到Python
?有谁知道如何实现这一切?
I have
Python
-based script which should be run onApache Spark
cluster.I have
Hadoop
MapReduce
InputFormat
as a data source forRDD
. Here is no problem.The problem is I'd like to construct custom
Hadoop
Configuration
with additional resource files loaded and attributes set. Intention is to use modifiedConfiguration
insidePython
SparkContext
.I can build
JVM
code which can construct and load neededHadoop
Configuration
. How to attach it toPython
usingPySpark
?Does anybody know how all of this could be achieved?
原文:https://stackoverflow.com/questions/29571644
最满意答案
关键字
static
在C中已经严重超载,C ++增加了一些额外的含义。 对于static
意味着什么的真实讨论,您需要指定上下文:在命名空间范围内,static
影响所谓的链接:声明的名称是指不同来源中的同一实体,还是仅涉及这一个特定来源。 在其他地方,对于数据,它指定实体的生命周期, 而不是实体名称的绑定:只有一个静态成员变量的实例,它独立于包含它的类的任何实例而存在。 如果成员函数是静态的,这意味着它没有指向特定实例的指针,并且可以在没有任何实例的情况下调用。关于您的具体问题:
静态成员不是该类的任何实例的一部分,因此它不会影响类的大小(实际上是其实例的大小)。 静态成员在范围和访问控制方面仍然是成员,但它具有静态生存期,并且存在于类的任何实例之外。
具体对象的
sizeof
不能为零,因为即使它不包含数据,也不能与内存中的任何其他对象具有相同的地址。 如果定义了这样的对象数组,则第一个元素的地址必须与第二个元素的地址不同(sizeof
返回必须添加到第一个元素的地址以获取第二个元素的地址的字节数) 。 对象的物理大小可以是0,至少在某些情况下:例如,基类的物理大小可以为0(假设它是该类型的唯一基础)。我不确定你在这里问的是什么。 当你写一些类似
ab
东西时,b
会在a的范围内被查找; 如果b
是静态成员,则a
仅用于确定范围。 当您编写A::b
,A::
还指定将在其中进行名称查找的范围。从技术上讲,静态数据成员的声明不是定义。 原因,或者至少原因,是它必须独立于类的任何实例而在内存中布局。 在早期,这是当时现有的编译器技术所要求的,即使在今天,您通常也不希望在定义类的头文件中使用初始化数据。
The keyword
static
was already seriously overloaded in C, and C++ adds a couple of additional meanings. For any real discussion of whatstatic
means, you need to specify the context: at namespace scope,static
affects what is called linkage: whether the name being declared refers to the same entity in different sources, or only in this one particular source. Elsewhere, for data, it specifies the lifetime of the entity, not the binding of the name of the entity: there is exactly one instance of a static member variable, which exists independently of any instances of the class which contains it. If a member function is static, this means that it has nothis
pointer to a specific instance, and can be called without any instance.With regards to your specific questions:
A static member is not part of any instance of the class, so it doesn't affect the size of the class (which is in fact the size of its instances). The static member is still a member in terms of scope and access controls, but it has static lifetime, and exists outside of any instance of the class.
The
sizeof
of a concrete object cannot be zero, since even if it contains no data, it cannot have the same address as any other object in memory; if you define an array of such objects, the address of the first element must be different from that of the second element (andsizeof
returns the number of bytes you must add to the address of the first element to get the address of the second). The physical size of an object can be 0, at least in certain cases: a base class can have a physical size of 0, for example (provided it is the only base of that type).I'm not sure what you're actually asking here. When you write something like
a.b
,b
is looked up in the scope ofa
; ifb
is a static member,a
is only used to determine the scope. When you writeA::b
, theA::
also specifies thhe scope in which name lookup will occur.Techically, the declaration of a static data member is not a definition. The reason, or at least the original reason, is that it must be laid out in memory independently of any instances of the class. In the early days, this was required by the then existing compiler technology, and even today, you generally don't want the initialization data in the header file where you define the class.
相关问答
更多-
C ++中的静态变量(Static variables in C++)[2022-03-12]
当我无故地回答你的问题时,请问,这样可以更容易理解。 当在头文件中声明静态变量时,其范围限制为.h文件或跨所有单位。 没有像“头文件范围”这样的东西。 头文件被包含在源文件中。 翻译单元是源文件, 包括头文件中的文本。 无论你在头文件中写什么,都会被复制到每个包含源文件中。 因此,头文件中声明的静态变量就像每个源文件中的静态变量一样。 由于声明一个变量static这种方式意味着内部链接,每个包含头文件的翻译单元都会获得自己的 单个变量(在翻译单元之外是不可见的)。 这通常不是你想要的。 我想知道一个头文件中 ... -
静态断言在C(Static assert in C)[2022-05-22]
C-1x添加_Static_assert关键字。 这似乎是在gcc-4.6中实现的: _Static_assert (0, "assert1"); /* { dg-error "static assertion failed: \"assert1\"" } */ 第一个插槽需要是一个积分的常量表达式。 第二个插槽是一个常量字符串文字,可以长( _Static_assert(0, L"assertion of doom!") )。 我应该注意,这也是在最新版本的俚语中实现的。 C11 standard ad ... -
C ++和Objective C中“静态”含义有什么不同?(What are the differences in the meaning of “static” in C++ and Objective C?)[2022-06-28]
static在Objective-C中具有与C中完全相同的含义。它与C ++中的含义不同。 在C ++中, static还用于声明和定义类方法(只能在类本身上调用的方法)和变量,但Objective-C使用不同的语法区分类和实例方法: + (void)classMethod; - (void)instanceMethod; 并且不支持类变量。 static has the exact same meaning in Objective-C that it would have in C. It does ... -
关键字static在C中已经严重超载,C ++增加了一些额外的含义。 对于static意味着什么的真实讨论,您需要指定上下文:在命名空间范围内, static影响所谓的链接:声明的名称是指不同来源中的同一实体,还是仅涉及这一个特定来源。 在其他地方,对于数据,它指定实体的生命周期, 而不是实体名称的绑定:只有一个静态成员变量的实例,它独立于包含它的类的任何实例而存在。 如果成员函数是静态的,这意味着它没有指向特定实例的指针,并且可以在没有任何实例的情况下调用。 关于您的具体问题: 静态成员不是该类的任何实例 ...
-
什么是C中的静态和动态绑定(严格C,而不是C ++)?(What are static and dynamic binding in C (strictly C,not C++)?)[2021-11-28]
形式上,“本地”C中没有这样的术语。 术语静态绑定(“早期绑定”)和动态绑定(“后期绑定”)的简化说明:它们最常用于面向对象的设计,以确定是否在编译时调用特定的继承成员函数的决定时间或运行时间。 虚函数的含义是它是一个被继承的函数,而不是被继承的基类中的等价函数。 如果编译器可以在编译时确定对象是“基类”类型还是类型“继承类”,那么您将获得静态绑定,否则将获得动态绑定。 所以你需要某种运行时类型信息(RTTI)。 在上面的上下文中,只有在C程序中使用面向对象的继承/多态时,这些术语才有意义。 C对此类机制没 ... -
static表示该函数具有内部链接。 这意味着它不会与其他文件(翻译单元)中相同标识符的其他用途链接。 例如,假设在Tree.c我有一个在Tree结构上运行的函数,我有一些名为UpdateNode本地子程序,它在Tree的一部分上运行。 进一步假设在List.c ,我有一个对List结构进行操作的函数,它还有一些名为UpdateNode本地子例程,它只适用于List结构,而不适用于Tree结构。 如果我将这两个子例程都与外部链接一起离开,那么链接器会抱怨多个定义。 通过用static内部连接标记它们,避免了 ...
-
在尝试将某些内容推送到CPP文件之前,您需要在CPP文件中的某个位置初始化静态成员。 添加如下内容: std::vector
Foo::unvalidatedSockets; You need to initialize your static member somewhere in the CPP file before you try to push something onto it. Add something like this: std::vector< ... -
C ++中静态库的问题(Problem with static library in C++)[2022-07-17]
尝试在项目属性的链接器输入中设置其他依赖项。 Try setting additional dependencies in the linker input for a project properties. -
您可能不希望在main函数中声明您的struct - 将其范围限制为函数的范围,这很少是您想要的。 然后,在C中, static指的是对象生命周期,而不是结构成员。 你想要的是一个static类成员,它是一个C ++(而不是 C)构造。 You might not want to declare your struct inside the main function -- that limits its scope to that of the function, which is seldom what ...
-
静态方法C ++(Static Method C++)[2021-10-18]
未定义的引用`Tool :: getStringIntoArray(std :: basic_string,std :: allocator>)' 它正在寻找Tool::getStringIntoArray但你定义了getStringIntoArray 。 更改定义中的签名 char* getStringIntoArray(string str) 至 char* Tool::getStringIntoArray(string str) undefined reference to `Tool::getS ...