我有一个项目,我必须提高其性能.我有一个庞大的Mysql数据库,由一个巨大的CSV文件(1亿行)构成.插入时间不是问题,但请求的响应时间非常重要,有时候使用2个连接的查询大约需要20个小时......
在减少响应时间的目标中,我尝试将数据库迁移到Cassandra但没有成功:我的数据模型不适合Cassandra概念.然后我想尝试另一种方法来提高性能:并行虚拟文件系统.而是在Mysql数据库中插入数据并发送然后发送查询,我试图用多线程读取整个csv文件并完成我的计算.但结果并不好:只有1 000 000行,2分20秒.
目前,我的计算非常简单:在使用MPI-IO API的C++中,我只计算2列中的不同对数值.为了进行计算,我使用了一个hashmap,其中每个键都是来自csv文件的一对值.最后,我返回hashmap大小.这里有一个小代码:
MPI::Init(argc,argv);
cout << " INFO init done" << endl;
int myrank = MPI::COMM_WORLD.Get_rank();
int numprocs = MPI::COMM_WORLD.Get_size();
get_filename(path_name, myrank);
cout << " INFO open file : " << path_name << endl;
MPI::File thefile = MPI::File::Open(MPI::COMM_WORLD, path_name.c_str(),
MPI::MODE_RDONLY,
MPI::INFO_NULL);
MPI::Offset offset = 101;
MPI::Offset limit = thefile.Get_size();
cout << " INFO go computing" << endl;
do {
thefile.Read_at(offset, buf, bufsize, MPI_CHAR, status);
temp.assign(buf);
Tokenize(temp,tokens,"\n");
line.assign(tokens.at(0));
tokens.clear();
Tokenize(line,tokens,"\t");
nidt_count(tokens);
tokens.clear();
offset += (line.size() + 1);
}while(offset …Run Code Online (Sandbox Code Playgroud) 我试图在Symfony 2中导入.csv文件.我已经创建了一个文件表单,现在我想将它保存在我的数据库中.
这是我的处理程序文件,我想在其中进行.csv处理并保留它:
public function process()
{
if ($this->request->getMethod() == 'POST')
{
$this->form->bindRequest($this->request);
$tableau = array();
$i = 0;
$c = 0;
$num = 0;
if (isset($_FILES['file']))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file,'r');
$row = 1;
$handle = fopen("$file", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$num =+ count($data);
$row++;
for ($c = $i; $c < $num; $c++)
{
$tableau[$c] = $data[$c];
$i++;
}
}
}
$tableau[$c+1] = $i;
/*
if ($this->form->isValid())
{
print_r($this->form->getData());
$this->onSuccess($this->form->getData());
return …Run Code Online (Sandbox Code Playgroud) 当我这样做时psql --no-align --field-separator ',',我得到CSV输出,其中包含一个包含字段名称的标题和一个预告片,告诉我找到了多少行.要将其传递给分析程序,我需要标题而不是预告片.我肯定可以编写一个过滤器来传递psql输出的前N-1行,但我更愿意压制预告片.是否有一个我错过的选项会打开标题--tuples-only或关闭预告片?
我正在尝试使用SuperCSV将大量行(约200万)从数据库写入CSV文件.我需要在编写每个单元格时执行验证,内置的CellProcessors非常好.我想捕获CellProcessors抛出的所有异常,以便我可以返回源数据并进行更改.
问题是,当一行中存在多个错误时(例如,第一个值超出范围,第二个值为null但不应该是),只有第一个CellProcessor将执行,因此我只会看到一个的错误.我希望在一次传递中处理整个文件,并在其结尾处有一组完整的异常.
这是我正在尝试的方法:
for (Row row : rows) {
try {
csvBeanWriter.write(row, HEADER_MAPPINGS, CELL_PROCESSORS);
} catch (SuperCsvCellProcessorException e) {
log(e);
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?谢谢!
编辑:这是我写的代码类似于猎犬的代码,以防它帮助任何人:
import java.util.List;
import org.supercsv.cellprocessor.CellProcessorAdaptor;
import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.exception.SuperCsvCellProcessorException;
import org.supercsv.util.CsvContext;
public class ExceptionCapturingCellProcessor extends CellProcessorAdaptor {
private final List<Exception> exceptions;
private final CellProcessor current;
public ExceptionCapturingCellProcessor(CellProcessor current, CellProcessor next, List<Exception> exceptions) {
super(next);
this.exceptions = exceptions;
this.current = current;
}
@Override
public Object execute(Object value, CsvContext context) {
// Check input is not null
try { …Run Code Online (Sandbox Code Playgroud) 我很难从猪中获取数据并将其转换为CSV,我可以在Excel或SQL(或R或SPSS等)中使用,而无需大量操作......
我尝试过使用以下功能:
STORE pig_object INTO '/Users/Name/Folder/pig_object.csv'
USING CSVExcelStorage(',','NO_MULTILINE','WINDOWS');
Run Code Online (Sandbox Code Playgroud)
它创建了具有该名称的文件夹,其中包含许多part-m-0000#文件.我以后可以使用cat part*> filename.csv加入它们,但是没有标题,这意味着我必须手动放入它.
我已经读过PigStorageSchema应该创建另一个带有标题的位但它似乎根本不起作用,例如,我得到的结果就好像它刚刚存储一样,没有头文件:STORE pig_object INTO'/ Users /名称/文件夹/ pig_object'使用org.apache.pig.piggybank.storage.PigStorageSchema();
(我在本地和mapreduce模式下都试过这个).
有没有办法将Pig中的数据导入一个简单的CSV文件而没有这些多个步骤?
任何帮助将非常感激!
有没有办法使用bash删除某些输入CSV文件的最后四列?最后四列可以包含从一行到另一行的长度不同的字段,因此仅从每行的末尾删除一定数量的字符是不够的.
我将如何转换:
$ find . -ls > /tmp/files.txt
Run Code Online (Sandbox Code Playgroud)
这给了我类似的东西:
908715 40 -rwxrwxr-x 1 david staff 16542 Nov 15 14:12 ./dump_info.py
908723 0 drwxr-xr-x 2 david staff 68 Nov 20 17:35 ./metadata
Run Code Online (Sandbox Code Playgroud)
进入csv输出?它看起来像:
908715,40,-rwxrwxr-x,1,david,staff,16542,Nov 15 14:12,./dump_info.py
908723,0,drwxr-xr-x,2,david,staff,68,Nov 20 17:35,./metadata
Run Code Online (Sandbox Code Playgroud)
这是一个在文件名中包含空格的示例标题:
652640,80,-rw-rw-r--,1,david,staff,40036,Nov,6,15:32,./v_all_titles/V Catalog Report 11.5.xlsx
Run Code Online (Sandbox Code Playgroud) 我必须将numpy浮点数组转换为字符串(存储在SQL DB中),然后将相同的字符串转换回numpy浮点数组.
这就是我要去一个字符串(基于这篇文章)
VIstring = ''.join(['%.5f,' % num for num in VI])
VIstring= VIstring[:-1] #Get rid of the last comma
Run Code Online (Sandbox Code Playgroud)
首先,这确实有效,这是一个好方法吗?他们是摆脱最后一个逗号的更好方法吗?或者我可以获得join为我插入逗号的方法吗?
其次,更重要的是,是否有一种聪明的方法从字符串返回浮点数组?
这是一个数组和字符串的示例:
VI
array([ 17.95024446, 17.51670904, 17.08894626, 16.66695611,
16.25073861, 15.84029374, 15.4356215 , 15.0367219 ,
14.64359494, 14.25624062, 13.87465893, 13.49884988,
13.12881346, 12.76454968, 12.40605854, 12.00293814,
11.96379322, 11.96272486, 11.96142533, 11.96010489,
11.95881595, 12.26924591, 12.67548634, 13.08158864,
13.4877041 , 13.87701221, 14.40238245, 14.94943786,
15.49364166, 16.03681428, 16.5498035 , 16.78362298,
16.90331119, 17.02299387, 17.12193689, 17.09448654,
17.00066063, 16.9300633 , 16.97229868, 17.2169709 , 17.75368411])
VIstring
'17.95024,17.51671,17.08895,16.66696,16.25074,15.84029,15.43562,15.03672,14.64359,14.25624,13.87466,13.49885,13.12881,12.76455,12.40606,12.00294,11.96379,11.96272,11.96143,11.96010,11.95882,12.26925,12.67549,13.08159,13.48770,13.87701,14.40238,14.94944,15.49364,16.03681,16.54980,16.78362,16.90331,17.02299,17.12194,17.09449,17.00066,16.93006,16.97230,17.21697,17.75368'
Run Code Online (Sandbox Code Playgroud)
哦,是的,精确度的损失%.5f …
我有代码在单个文件上执行该过程,任何人都可以更改此脚本,以便循环遍历文件类型为" .LTR " 的目录"H:\ Letter Display\Letters"中的所有文件,并将它们全部保存:
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("H:\Letter Display\Letters\LTRPRT__00000008720000000001NI-K-RMND.LTR", ForReading)
str1000 = "1000"
str1100 = "1100"
str1200 = "1200"
str9990 = "9990"
arrCommas1 = Array(14,31,41,59,70,81,101,111,124,138)
arrCommas2 = Array(14,31,41,55,79,144,209,274,409,563,589,608,623)
arrCommas3 = ArraY (14,32,41,73,83,97,106,156,167,184,188,195,207,260,273,332,368,431,461,472,593,617,666,772,810,834,848,894,898)
arrCommas4 = Array(14,31,41)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If Left(strLine, 4) = str1000 then
intLength = Len(strLine)
For Each strComma in arrCommas1
strLine = Left(strLine, strComma - 1) + "," _
+ Mid(strLine, …Run Code Online (Sandbox Code Playgroud) 我有一堆CSV数据需要加载到MySQL数据库中.好吧,也许是CSV-ish.(编辑:实际上,它看起来像RFC 4180中描述的东西)
每行都是以逗号分隔的双引号字符串列表.要转义出现在列值中的任何双引号,请使用双引号.允许反斜杠代表自己.
例如,行:
"", "\wave\", ""hello,"" said the vicar", "what are ""scare-quotes"" good for?", "I'm reading ""Bossypants"""
Run Code Online (Sandbox Code Playgroud)
如果解析成JSON应该是:
[ "", "\\wave\\", "\"hello,\" said the vicar", "what are \"scare-quotes\" good for?", "I'm reading \"Bossypants\"" ]
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用它LOAD DATA来读取CSV,但我遇到了一些奇怪的行为.
举个例子,考虑一下我是否有一个简单的两列表
shell% mysql exampledb -e "describe person"
+-------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+-------+
| ID | int(11) | YES | | NULL | |
| UID | char(255) …Run Code Online (Sandbox Code Playgroud) csv ×10
apache-pig ×1
awk ×1
bash ×1
batch-file ×1
c++ ×1
cut ×1
excel ×1
find ×1
formatting ×1
import ×1
java ×1
linux ×1
mpi ×1
mysql ×1
numpy ×1
performance ×1
postgresql ×1
python ×1
python-2.7 ×1
rfc4180 ×1
sed ×1
sql ×1
supercsv ×1
symfony ×1
unix ×1
vbscript ×1