我很想知道为什么localhost.com(没有www)重定向到google.com.我还注意到www.localhost.com没有找到404页面.我在Firefox,Chrome和Internet Explorer中检查过这一切都是一样的.我检查了域名记录,它显示它属于Tucows,我很确定谷歌不拥有它,我知道我们可以使用http重定向将其更改为www或非www版本,因为网站所有者希望.
我最近才知道在Java 8哈希映射中使用二叉树而不是链表,并使用哈希代码作为分支因子.我知道在高冲突的情况下,查找从O(n)减少到O(log n)通过使用二叉树.我的问题是它真正做了什么好处,因为摊销的时间复杂度仍然是O(1)并且如果你强制通过为所有键提供相同的哈希码来存储同一桶中的所有条目可以看到一个显着的时间差异,但没有一个人在他们正确的思想中会这样做.
二进制树比单链表使用更多空间,因为它存储左右节点.当除了一些虚假测试用例之外,当时间复杂度完全没有改善时,为什么增加空间复杂度.
我的表是:
customer(cid,name,city,state)
orders(oid,cid,date)
product(pid,productname,price)
lineitem(lid,pid,oid,number,totalprice)
Run Code Online (Sandbox Code Playgroud)
我想选择城市'X'的所有客户购买的产品.这意味着我需要交叉生活在城市'X'的所有客户购买的产品
示例:如果有3个客户c1,c2和c3我的答案是c1.product(intersect)c2.product(intersect)c3.product
我想实现这个只是使用where exists或where not exists因为我需要编写关于相同where not in或where in不可用的关系演算.我的部分查询是这样的:
select
*
from
product p,
lineitem l,
customer c1
where
exists(
select
*
from
customer c,
orders o
where
o.cid=c.cid and
c.city='X' and
l.oid=o.oid and
l.pid=p.pid and
c1.cid=c.cid)
Run Code Online (Sandbox Code Playgroud)
以上查询为我提供了生活在X市的所有客户的pid,cid,oid,lid,totalprice,city,productname.现在我需要弄清楚如何选择所有客户共有的产品.
注意:
我不能使用任何聚合函数,因为它在关系演算中不可用.我有一个使用聚合函数的工作查询,这是
select
p.productname
from
product p,
orders s,
lineitem l,
customer c
where
l.pid=p.pid and
l.oid=s.oid and
c.cid=s.cid and
c.city='X'
group by
p.productname
having
count(distinct c.cid)=(select count(*) from …Run Code Online (Sandbox Code Playgroud) INPUT:
输入数据集包含多个文件中的 1000 万笔交易,以镶木地板形式存储。包括所有文件在内的整个数据集的大小范围为 6 到 8GB。
问题陈述:
根据客户 ID 对交易进行分区,这将为每个客户 ID 创建一个文件夹,每个文件夹包含该特定客户完成的所有交易。
HDFS 对根目录中可以创建的子目录数量有 640 万个硬性限制,因此使用客户 ID 的最后两位数字(范围从 00、01、02...到 99)来创建顶级目录和每个顶级目录将包含所有以该特定两位数字结尾的客户 ID。
示例输出目录结构:
00/cust_id=100900/part1.csv
00/cust_id=100800/part33.csv
01/cust_id=100801/part1.csv
03/cust_id=100803/part1.csv
代码:
// Reading input file and storing in cache
val parquetReader = sparksession.read
.parquet("/inputs")
.persist(StorageLevel.MEMORY_ONLY) //No spill will occur has enough memory
// Logic to partition
var customerIdEndingPattern = 0
while (cardAccountEndingPattern < 100) {
var idEndPattern = customerIdEndingPattern + ""
if (customerIdEndingPattern < 10) {
idEndPattern = "0" + customerIdEndingPattern
}
parquetReader …Run Code Online (Sandbox Code Playgroud) partitioning hadoop-partitioning apache-spark hadoop2 apache-spark-sql
我认为trimToSize()Java的ArrayList中的方法是不必要的.我的理解是:
我们来看一个整数数组:
int[] a = new int[10]; //This allocates ten free slots proactively.
Run Code Online (Sandbox Code Playgroud)
ArrayList的主要优点是它可以在运行时动态创建数组,从而节省内存.现在代码
ArrayList<Integer> arl = new ArrayList<Integer>(10);不会主动分配十个空闲插槽; 相反,只有在存储数据时才添加插槽.
现在Java规范说trimToSize()将从ArrayList中删除未使用的空间,但根据我的理解,ArrayList中不会有任何未使用的空间,因为只有在数据可用时才创建空间,并且当数据可用时,未使用或可用空间将为零.
我有一个表,其中一列是total_price,它存储了存储在另一个表中的项目的价格总和.我想知道如何在SQL中执行此操作.我希望总价格列自动计算价格总和并存储在其列中.换句话说,我需要一个总和所需值的列并默认存储它.
例:
订单项表格包含数量,pid和总价格字段.
产品表有一个pid和price字段.
订单项表中的总价格字段应存储(lineitem.quantity*product.price)值.
我的正则表达式是这样的:
((?:[a-z][a-z0-9_]*)).*?(\d+).*?((?:[a-z][a-z0-9_]*)).*?(\d+).*?([a-z])
Run Code Online (Sandbox Code Playgroud)
如果我把它作为 MySQL RegExp 的输入,我会得到重复操作符错误。我知道它是因为 ?: 发生的,我用 ^ 替换了它,我也替换了 * ? 用 [^>]* 我替换的正则表达式是这样的:
'((^[a-z][a-z0-9_]*)).[^>]*.(\\d+).[^>]*.((^[a-z][a-z0-9_]*)).[^>]*.(\\d+).[^>]*.([a-z])'
Run Code Online (Sandbox Code Playgroud)
上面的表达式执行没有错误,但匹配失败并返回错误的结果。所以我想将第一个正则表达式转换为 mysql 支持的 POSIX 标准,而不会失去约束。
我的代码是:
x=new BigDecimal(x.toString()+" "+(new BigDecimal(10).pow(1200)).toString());
Run Code Online (Sandbox Code Playgroud)
我试图在将它们转换为字符串之后将两个bigdecimals连接起来然后将它们转换回bigdecimal.我这样做是因为x有一个带小数点的值并且乘法将改变它的值.它编译得很好但在执行时抛出一个数字格式的异常.
我的想法是使用BigDecimal("String x")构造函数将字符串转换回BigDecimal.
注意:(例如)x = 1333.212,我将其转换为x = 1333.2120000
java ×3
mysql ×3
sql ×3
apache-spark ×1
arraylist ×1
bigdecimal ×1
browser ×1
database ×1
dns ×1
hadoop2 ×1
hashmap ×1
intersection ×1
java-8 ×1
localhost ×1
partitioning ×1
regex ×1
theory ×1
url ×1
web ×1