本文将分享在withColumn下将数据框列和外部列表传递给udf的详细内容,此外,我们还将为大家带来关于@ColumncolumnDefinition使哪些属性多余?、c#–如何使用EntityFr
本文将分享在withColumn下将数据框列和外部列表传递给udf的详细内容,此外,我们还将为大家带来关于@Column columnDefinition使哪些属性多余?、c# – 如何使用Entity Framework 6将数据列表传递给存储过程、Column length too big for column ''Flist'' (max = 21845);、CSS 列宽属性详解:column-width 和 column-count的相关知识,希望对你有所帮助。
本文目录一览:- 在withColumn下将数据框列和外部列表传递给udf
- @Column columnDefinition使哪些属性多余?
- c# – 如何使用Entity Framework 6将数据列表传递给存储过程
- Column length too big for column ''Flist'' (max = 21845);
- CSS 列宽属性详解:column-width 和 column-count
在withColumn下将数据框列和外部列表传递给udf
我有一个具有以下结构的Spark数据框。bodyText_token具有标记(已处理/单词集)。而且我有一个嵌套的已定义关键字列表
root |-- id: string (nullable = true) |-- body: string (nullable = true) |-- bodyText_token: array (nullable = true)keyword_list=[[''union'',''workers'',''strike'',''pay'',''rally'',''free'',''immigration'',],[''farmer'',''plants'',''fruits'',''workers''],[''outside'',''field'',''party'',''clothes'',''fashions'']]
我需要检查每个关键字列表下有多少标记,并将结果添加为现有数据框的新列。例如:如果tokens =["become","farmer","rally","workers","student"]
结果为->[1,2,0]
以下功能按预期工作。
def label_maker_topic(tokens,topic_words): twt_list = [] for i in range(0, len(topic_words)): count = 0 #print(topic_words[i]) for tkn in tokens: if tkn in topic_words[i]: count += 1 twt_list.append(count) return twt_list
我在下面使用udfwithColumn
访问该函数,但出现错误。我认为这与将外部列表传递给udf有关。有没有一种方法可以将外部列表和dataframe列传递给udf,并向dataframe中添加新列?
topicWord = udf(label_maker_topic,StringType())myDF=myDF.withColumn("topic_word_count",topicWord(myDF.bodyText_token,keyword_list))
答案1
小编典典最干净的解决方案是使用闭包传递其他参数:
def make_topic_word(topic_words): return udf(lambda c: label_maker_topic(c, topic_words))df = sc.parallelize([(["union"], )]).toDF(["tokens"])(df.withColumn("topics", make_topic_word(keyword_list)(col("tokens"))) .show())
这不需要更改keyword_list
或使用UDF包装功能。您也可以使用此方法传递任意对象。例如,这可以用于传递sets
有效查找的列表。
如果要使用当前的UDF并topic_words
直接传递,则必须先将其转换为列文字:
from pyspark.sql.functions import array, litks_lit = array(*[array(*[lit(k) for k in ks]) for ks in keyword_list])df.withColumn("ad", topicWord(col("tokens"), ks_lit)).show()
根据您的数据和要求,可以选择其他更有效的解决方案,这些解决方案不需要UDF(爆炸+聚合+折叠)或查找(散列+向量运算)。
@Column columnDefinition使哪些属性多余?
我经常这样指定我的@Column
注释:
@Column(columnDefinition="character varying (100) not null",length=100,nullable=false)
如您所见length
,nullable
即使columnDefinition
已经指定了,我也指定了。那是因为我不知道这些值的确切位置/时间。
因此,在指定时columnDefinition
,的其他哪些属性@Column
将变得多余?
如果有关系,我可以使用Hibernate和PostgreSQL
答案1
小编典典我的回答:应重写以下所有内容(即在columndefinition
适当的情况下,全部描述):
length
precision
scale
nullable
unique
也就是说,列DDL将包含:name
+ columndefinition
和其他所有内容 。
基本原理如下。
包含单词“ Column”或“ Table”的注释纯粹是物理的-属性 仅 用于根据数据库控制DDL / DML。
其他纯逻辑注释-在Java内存中用于控制JPA处理的属性。
这就是为什么有时会出现两次将可选性/可空性设置的原因-一次通过
@Basic(...,optional=true)
和一次通过@Column(...,nullable=true)
。前者说,在刷新时,JPA对象模型(内存中)的属性/关联可以为空;后者表示DB列可以为null。通常,您希望它们设置相同- 但并非总是如此 ,这取决于数据库表的设置和重用方式。
在您的示例中,length和nullable属性被覆盖和冗余。
因此,当指定columnDefinition时,@Column的其他哪些属性将变得多余?
在JPA Spec和javadoc中:
columnDefinition
定义: 生成列的DDL时使用的SQL片段。columnDefinition
默认值: 生成的SQL以创建推断类型的列。提供以下示例:
@Column(name="DESC", columnDefinition="CLOB NOT NULL", table="EMP_DETAIL")
@Column(name=”EMP_PIC”, columnDefinition=”BLOB NOT NULL”)
而且,嗯…就是这样。:-$?!
columnDefinition是否会覆盖同一批注中提供的其他属性?
Javadoc和JPA规范未明确解决此问题-规范没有提供很好的保护。要100%确定,请使用您选择的实现进行测试。
从JPA规范中提供的示例可以安全地暗示以下内容
name
&table
可以与结合使用columnDefinition
,都不会被覆盖nullable
被…覆盖/使其冗余columnDefinition
从“情境逻辑”中可以很安全地隐含以下内容(我只是说那句话?? :-P):
length
,precision
,scale
是覆盖/冗余由columnDefinition
-它们是一体的类型insertable
和updateable
分别提供,并且从不包含在内columnDefinition
,因为它们在将SQL生成数据库之前控制它们在内存中的生成。- 剩下的只是“
unique
”属性。它类似于nullable-扩展/限定类型定义,因此应将其视为类型定义的组成部分。即应该被覆盖。
测试我的答案分别 对列“ A”和“ B”:
@Column(name="...", table="...", insertable=true, updateable=false, columndefinition="NUMBER(5,2) NOT NULL UNIQUE" @Column(name="...", table="...", insertable=false, updateable=true, columndefinition="NVARCHAR2(100) NULL"
- 确认生成的表具有正确的类型/可空性/唯一性
- (可选)执行JPA插入和更新:前者应包含A列,后一列B
c# – 如何使用Entity Framework 6将数据列表传递给存储过程
在SSMS中创建并测试了用户定义的表类型和存储过程.问题发生在C#中.更新模型(.edmx文件)时,会发出以下警告:
Warning 4 Error 6005: The function ‘uspGetBusyPersonsTVP’ has a parameter ‘list’ at parameter index 2 that has a data type ‘table type’ which is currently not supported for the target Entity Framework version. The function was excluded.
模型浏览器中的检查显示已在模型中创建存储过程,但仅使用非TVP参数.
此MSDN站点https://msdn.microsoft.com/en-us/data/hh859577.aspx表示自EF 5.0以来已支持表值参数,但本文仅讨论返回数据.
我刚刚完成更新,现在我正在使用Visual Studio 2015社区,.Net 4.6和Entity Framework 6.1.3.
有谁知道TVP是否可以传递给存储过程,或者是否有可能被支持?
解决方法
EF是否会支持它我无法回答,因为我不为微软工作.无论是否可以,基于How to pass table value parameters to stored procedure from .net code的答案似乎是“是”,但是看起来你需要使用原始的ADO.NET来做到这一点.
Column length too big for column ''Flist'' (max = 21845);
建表语句报如下错误:
CREATE TABLE test_1 (
Fid bigint(20) unsigned NOT NULL,
Ftype tinyint(4) unsigned NOT NULL,
Flist varchar(65532) DEFAULT NULL,
Fstatus tinyint(3) unsigned DEFAULT ''0'',
Ftime bigint unsigned DEFAULT ''0'',
Faddtime bigint unsigned DEFAULT ''0'',
PRIMARY KEY (Fid,Ftype)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
建表报如下错误:
ERROR 1074 (42000): Column length too big for column ''Flist'' (max = 21845); use BLOB or TEXT instead
原因分析
虽然知道mysql建表的时候列长度有65535的限制,但是一直没有时间整理这个问题,接着今天整理一下。
ERROR 1074 (42000): Column length too big for column ''Flist'' (max = 21845); use BLOB or TEXT instead
从上面的报错我们知道Flist列指定值不能大于21845 字节(mysql官方手册中定义,创建表的字段长度限制为65535 bytes,这个是指所有列指定的长度和,当然不包括TEXT和BLOB类型的字段)。
还有一点我们需要注意的是我们定义列长度时指定的长度单位为字符,上面提到的65535限制的单位为字节。不同字符集下每个字符占用的字节数不同,utf8下每个字符占用3个字节(65535/3=21845),gbk下每个字符占用2个字节(65535/2=32767),latin1字符集下一个字符占用一个字节。
操作验证
<span>实验1:
CREATE TABLE test_1 (
Flist varchar(21845) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ERROR 1118 (42000): Row size too large. The maximum row size for the used
table type, not counting BLOBs, is 65535. This includes storage overhead,
check the manual. You have to change some columns to TEXT or BLOBs
</span><span>##我们发现给表指定一个列,
列长度为21845字符(utf8下最大长度限制),但是建表依然报错。这是因为还有别的一些开销,
所以我们不能指定列长度为最大限制21845(测试发现指定长度为21844后建表成功)</span>
<span>实验2:
CREATE TABLE test_1 (
Fid bigint(20) unsigned NOT NULL,
Ftype tinyint(4) unsigned NOT NULL,
Flist varchar(21844) DEFAULT NULL,
Fstatus tinyint(3) unsigned DEFAULT ''0'',
Ftime bigint unsigned DEFAULT ''0'',
Faddtime bigint unsigned DEFAULT ''0'',
PRIMARY KEY (Fid,Ftype)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
报如下错误:
ERROR 1118 (42000): Row size too large. The maximum row size for the used
table type, not counting BLOBs, is 65535. This includes storage overhead,
check the manual. You have to change some columns to TEXT or BLOBs
</span><span>##虽然Flist 长度指定为21844,但是因为还
有其他非TEXT和BLOB字段存在,所以报错。这是因为65535长度限制是针对表中所有列的长
度和的最大限制,如果列的长度和超过该值,建表依然会报错。(除了TEXT和BLOB类型的字
段的)</span>
CSS 列宽属性详解:column-width 和 column-count
CSS 列宽属性详解:column-width 和 column-count,需要具体代码示例
在网页设计中,我们常常需要将内容划分为多列,以提高信息的呈现效果。CSS中的列布局属性为我们提供了灵活的方案。其中,column-width 和 column-count 是两个常用的列宽属性。本文将详细介绍这两个属性的用法,并提供相应的代码示例。
一、column-width 属性
column-width 属性用于设置每列的宽度。其语法如下:
立即学习“前端免费学习笔记(深入)”;
div { column-width: value; }
其中,value 可以是具体的宽度值,如像素(px)、百分比(%)、自动(auto),也可以是关键字如 inherit、initial 等。
代码示例:
<div> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mattis est id sem consequat, sit amet lobortis arcu bibendum.</p> <p>Integer ut sapien nec lectus euismod interdum. Vestibulum efficitur est massa, nec accumsan eros cursus eget.</p> <p>Donec eleifend eros eget enim eleifend, ac sollicitudin libero aliquam. Suspendisse potenti. Aliquam eget placerat mi.</p> </div> <style> .container { column-width: 200px; } </style>
上述代码将一个容器 div 分为三列,每列宽度为 200px。如果容器宽度不足以容纳三列,浏览器将自动调整列的宽度以适应容器。
二、column-count 属性
column-count 属性用于设置列的个数。其语法如下:
div { column-count: value; }
其中,value 表示列的个数,可以是具体数字,也可以是关键字,如 auto、inherit、initial 等。
代码示例:
<div> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mattis est id sem consequat, sit amet lobortis arcu bibendum.</p> <p>Integer ut sapien nec lectus euismod interdum. Vestibulum efficitur est massa, nec accumsan eros cursus eget.</p> <p>Donec eleifend eros eget enim eleifend, ac sollicitudin libero aliquam. Suspendisse potenti. Aliquam eget placerat mi.</p> </div> <style> .container { column-count: 2; } </style>
上述代码将容器 div 分为两列,如果容器内的内容超过两列所能容纳的宽度,浏览器将自动将内容划分到下一列。
三、column-width 和 column-count 的结合使用
column-width 和 column-count 可以结合使用,实现更复杂的列布局。当使用 column-count 属性时,列的个数优先级高于列宽属性,同时浏览器会自动计算列宽度以填满容器。
代码示例:
<div> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mattis est id sem consequat, sit amet lobortis arcu bibendum.</p> <p>Integer ut sapien nec lectus euismod interdum. Vestibulum efficitur est massa, nec accumsan eros cursus eget.</p> <p>Donec eleifend eros eget enim eleifend, ac sollicitudin libero aliquam. Suspendisse potenti. Aliquam eget placerat mi.</p> </div> <style> .container { column-count: 3; column-width: 200px; } </style>
上述代码将容器 div 分为三列,每列宽度为 200px,如果容器宽度不足以容纳三列,浏览器将自动调整列的宽度以适应容器。
总结:
在网页设计中,使用 column-width 和 column-count 属性可以方便地实现多列布局效果。通过设置列宽和列个数,可以使页面内容更加有条理,提升用户体验。上文提供了具体的代码示例,读者可以根据实际需求进行调整和使用。好了,相信通过本文的介绍,大家对于 CSS 的列宽属性有了更深入的了解。快来试试吧!
以上就是CSS 列宽属性详解:column-width 和 column-count的详细内容,更多请关注php中文网其它相关文章!
关于在withColumn下将数据框列和外部列表传递给udf的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于@Column columnDefinition使哪些属性多余?、c# – 如何使用Entity Framework 6将数据列表传递给存储过程、Column length too big for column ''Flist'' (max = 21845);、CSS 列宽属性详解:column-width 和 column-count的相关知识,请在本站寻找。
本文标签: