首页 \ 问答 \ mysqlimport可以接受JSON输入吗?(Can mysqlimport accept JSON input?)

mysqlimport可以接受JSON输入吗?(Can mysqlimport accept JSON input?)

我们目前有一些由管道分隔文本组成的日志,它具有格式

field1:value1|field2:value2|...|fieldN:valueN\n
field1:value1|field2:value2|...|fieldN:valueN\n
etc.

我有一个导入程序脚本(运行perl然后运行mysqlimport的bash),它目前从每行的开头删除几个单词,然后在生成的文本文件上运行mysqlimport。

我们正在将日志记录升级到输出JSON的数据服务。 导入器脚本仍将该JSON的内容导入MySQL数据库表。 采用那个漂亮的JSON并将其转换为管道分隔文件以与mysqlimport一起使用感觉就像是一种糟糕的形式 - 但我有任何选择吗? 我在mysql文档或论坛中找不到任何东西。


We currently have certain logs composed of pipe-delimited text, which has the format

field1:value1|field2:value2|...|fieldN:valueN\n
field1:value1|field2:value2|...|fieldN:valueN\n
etc.

I have an importer script (bash that runs perl and then mysqlimport), which currently removes a few words from the beginning of each row and then runs mysqlimport on the resulting text file.

We are upgrading our logging to a data service that outputs JSON. The importer script will still be importing the content of that JSON into a MySQL database table. It feels like bad form to take that nice JSON and convert it into a pipe-delimited file for use with mysqlimport - but do I have any options? I couldn't find anything in the mysql documentation or forums.


原文:https://stackoverflow.com/questions/13826942
更新时间:2022-12-11 13:12

最满意答案

使用isa方法。 它在UNIVERSAL包中定义(请参阅perldoc UNIVERSAL )。 所有Perl类都隐式地从UNIVERSAL继承。

use Scalar::Util qw( blessed );

if (blessed($val) and $val->isa('Path::Class')) {
    print "It's a Path::Class object!\n";
}

Use the isa method. It's defined in the UNIVERSAL package (see perldoc UNIVERSAL). All Perl classes implicitly inherit from UNIVERSAL.

use Scalar::Util qw( blessed );

if (blessed($val) and $val->isa('Path::Class')) {
    print "It's a Path::Class object!\n";
}

相关问答

更多
  • 代码中存在可能由于类型检查而被捕获的错误 您收到的错误消息提请注意第8行: @vals[2*$i, 3*$i ... $max-1] = 0; 该行将=右侧的值列表分配给左侧元素列表。 左侧列表中的第一个元素@vals[2*$i]获得一个零。 您没有在右侧定义更多的值,因此左侧的其余元素被分配了一个Mu 。 Mu适合作为没有特定类型但没有特定价值的元素的占位符。 除了其他方面,将Mu看作是Null,除了它是类型安全的。 您使用此高尔夫版本获得相同的场景: my @vals; @vals[0,1] = 0; ...
  • 使用isa方法。 它在UNIVERSAL包中定义(请参阅perldoc UNIVERSAL )。 所有Perl类都隐式地从UNIVERSAL继承。 use Scalar::Util qw( blessed ); if (blessed($val) and $val->isa('Path::Class')) { print "It's a Path::Class object!\n"; } Use the isa method. It's defined in the UNIVERSAL pack ...
  • 为了清楚起见,您是否在随机Perl代码中查看随机包? 或者对于Perl 模块 ,例如“a / b / c / d1.pm”,模块“a :: b :: c :: d1”? 在任何一种情况下,您都不能使用单个“use”语句来加载它们。 您需要做的是使用glob或File::Find找到所有适当的文件。 在第一种情况(模块)中,您可以通过require每个文件加载它们,或者通过将文件名转换为模块名称( s#/#::#g; s#\.pm$##; )并调用单独use每个模块。 对于嵌套在随机Perl文件中的实际包,这 ...
  • 伊丽莎白的答案是坚实的,但直到该功能创建之前,我不明白为什么你不能创建一个Key类用作散列键,它将有一个基于它的值而不是它的位置的显式散列函数在记忆中。 这个哈希函数,用于列表中的位置和相等性测试,都是.WHICH 。 这个函数必须返回一个ObjAt对象,它基本上只是一个字符串。 class Key does Positional { has Int @.list handles ; method n ...
  • 使用Phone.TYPE int phoneType = phones.getInt(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)); Use Phone.TYPE int phoneType = phones.getInt(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
  • 代码的固定版本和评论是: package X; # You need to return a blessed object sub new { my $self = bless {}, "X"; return $self; } # You need to define xyz before calling it sub xyz { print "X"; } package Y; sub new { my $self = bless ...
  • 不是,不是 - 没有后向引用检查或JS中提供的任何类似内容。 这种方法的唯一方法是,如果您可以访问所有相关对象,在某种集合中,并且可以检查每个对象的属性值。 这只返回第一个具有匹配值的对象,但不保证它是值的来源。 var myObjs = [ {name: 'one'}, {name: 'two'}, {name: 'three'} ]; function findObjWithVal(val, objs) { for (var i = 0; i < objs.length; ...
  • 这闻起来像是一团糟。 现在可能是重新考虑你的战略的时候了。 例如,也许你应该写My::Parser ,它返回My::Data对象。 但是如果你不想这样做,你可以手动使用bless来改变对象的类: my $obj = Some::Data->new; bless $obj, 'My::Data'; 在perldoc见保佑 。 This smells like a bit of a kludge. It might be time to rethink your strategy. For example, ...
  • $q->cgi确实是一个方法调用。 CGI subs可以作为方法或函数调用。 它检查参数并使用本地对象(如果未在调用中使用)。 $q->cgi is indeed a method call. CGI subs can be called as methods or as functions. It checks the arguments and uses a local object if one wasn't used in the call.
  • 因此,这为Perl提供了大致相同的语法。 但是,它并没有帮助您解决一些冲突的标准。 请注意以下事项: class ABC {...}被perl语法包ABC取代; 首都驼峰式方法名称变成了适当的“蛇案”perl。 应用程序已转向sigil-ed $ App 这已针对Moose v62,Perl 5.10进行了测试。 从最后一行开始的第二行将失败,因为View2类没有实现do_something_for_view 。 当你专门调用view1或view2 ,我看不到你似乎指出的应用程序是多态。 package V ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)