have,had,has的用法和区别

发布网友 发布时间:2022-04-22 06:04

我来回答

11个回答

懂视网 时间:2022-04-08 13:39

1、注意,需要声明为静态内部类,否则会报java.lang.NoSuchMethodException...<init>的错误
public static class MySqlWritable implements Writable, DBWritable {

2、如果输出目录存在,需要先删除

3、由于需要从mysql数据取值,则需要有mysql数据库驱动包,hadoop classpath查看hadoop类加载路径,将驱动包拷贝到其中一个目录下即可;

4、解决mysql"Access denied for user‘root‘@‘IP地址‘"问题
a、登录mysql
mysql -u username -p passwd

b、然后执行如下命令:
b-1、 GRANT ALL PRIVILEGES ON *.* TO ‘myuser‘@‘%‘ IDENTIFIED BY ‘mypassword‘ WITH GRANT OPTION;
b-2、FLUSH   PRIVILEGES;

Java代码:

package cn.sniper.hadoop.inputformat;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.db.DBConfiguration;
import org.apache.hadoop.mapreduce.lib.db.DBInputFormat;
import org.apache.hadoop.mapreduce.lib.db.DBWritable;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import cn.sniper.hadoop.util.HdfsUtil;

public class MyDBInputFormat {

    public static String IN_PATH = "hdfs://192.168.1.231:9000/README.txt";
    public static String OUT_PATH = "hdfs://192.168.1.231:9000/out";
    
    public static class MyMap extends Mapper<LongWritable, MySqlWritable, Text, IntWritable> {
        protected void map(LongWritable key, MySqlWritable value, org.apache.hadoop.mapreduce.Mapper<LongWritable,MySqlWritable,Text,IntWritable>.Context context) throws java.io.IOException ,InterruptedException {
            System.out.println(value);
            context.write(new Text(value.toString()), new IntWritable(1));
        };
    }
    
    /**
     * 注意,需要声明为静态内部类,否则会报java.lang.NoSuchMethodException...<init>的错误
     * @author sniper
     *
     */
    public static class MySqlWritable implements Writable, DBWritable {
        
        private String id;
        
        private String name;
        
        private String nickName;
        
        @Override
        public void readFields(ResultSet resultSet) throws SQLException {
            id = resultSet.getString(1);
            name = resultSet.getString(2);
            nickName = resultSet.getString(3);
        }

        @Override
        public void write(PreparedStatement statement) throws SQLException {
            statement.setString(1, id);
            statement.setString(2, name);
            statement.setString(3, nickName);
        }

        @Override
        public void readFields(DataInput dataInput) throws IOException {
            id = dataInput.readUTF();
            name = dataInput.readUTF();
            nickName = dataInput.readUTF();
        }

        @Override
        public void write(DataOutput dataOutput) throws IOException {
            dataOutput.writeUTF(id);
            dataOutput.writeUTF(name);
            dataOutput.writeUTF(nickName);
        }

        @Override
        public String toString() {
            return "MySqlWritable [id=" + id + ", name=" + name + ", nickName="
                    + nickName + "]";
        }
    }
    
    public static void main(String[] args) throws Exception {        
        Configuration conf = new Configuration();
        
        String driverClass = "com.mysql.jdbc.Driver";
        String dbUrl = "jdbc:mysql://192.168.1.105:3306/my";
        String userName = "root";
        String passwd = "123456";
        DBConfiguration.configureDB(conf, driverClass, dbUrl, userName, passwd);
        
        Job job = Job.getInstance(conf, MyDBInputFormat.class.getName());
        job.setJarByClass(MyDBInputFormat.class);
        
        //默认是TextInputFormat
        job.setInputFormatClass(DBInputFormat.class);
        String inputQuery = "select c_id, c_name, c_nickName from t_test";
        String inputCountQuery = "select count(*) from t_test";
        
        DBInputFormat.setInput(job, MySqlWritable.class, inputQuery, inputCountQuery);
        
        /*String tableName = "t_test";
        String conditions = "";
        String orderBy = "";
        String[] fieldNames = new String[]{"c_id", "c_name", "c_nickName"};
        DBInputFormat.setInput(job, MySqlWritable.class, tableName, conditions, orderBy, fieldNames);*/
        
        job.setOutputFormatClass(TextOutputFormat.class);
        FileOutputFormat.setOutputPath(job, new Path(OUT_PATH));
        
        job.setMapperClass(MyMap.class);
        
        //map输出的key如果不做设置,默认和reduce的key、value一致
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        
        job.waitForCompletion(true);
    }
}


关于hadoop中的DBInputFormat试验

标签:

热心网友 时间:2022-04-08 10:47

have had has这三个单词中文意思都是“拥有(表示一种状态)”的意思,但英文上用法有些区别,具体如下:

1.在英语句子中,若句子的时态是一般现在时,则have/has适用于这种情况下,其中当主语是第一人称,第二人称,第三人称复数(I,They,have)时,使用have,当主语时第三人称单数(she/he),则使用has,如下列例句:

I/You/They have a big apple.我/你/他们 有一个大苹果。

She/He has a small apple.她/他有一个小苹果。

2.若句子的时态时一般过去式,则无论人称是哪一种,都是用had。如下列例句:

I/You/They/She/He had a car. 我/你/他们/她/他过去有辆车。

3.若句子是完成式的形式。则has/have been是表示现在完成时,has用于第三人称单数,had been则用于过去完成时。如例句:

I have been studying English for ten years.我一直在学英语,已达十年之久。

扩展资料:

1.have英 [həv]   美 [hæv]  

2.aux.用以构成完成式及完成式的不定式,表示已经…

3.vt.有,具有;拿,取得;从事;必须,不得不

4.n.〈口〉有产者,有钱人;富国;〈英俚〉欺骗,诈骗

5.第三人称单数: has 现在分词: having 过去式: had 过去分词: had

参考资料:have-百度翻译



热心网友 时间:2022-04-08 12:05

have、had、has的用法和区别:

1、根据主语形式不同变形不同。如果是一般现在时,第三人称单数的时候用has,其它(如第一人称和第二人称)用have。

2、主语是过去式时形式不同。如果是一般过去时,全部都用had。

3、主语是完成式时形式不同。has/have been是现在完成时,has用于第三人称单数,had been过去完成时

扩展资料:

have

英 [həv]   美 [hæv]  

aux.用以构成完成式及完成式的不定式,表示已经…

vt.有,具有;拿,取得;从事;必须,不得不

n.〈口〉有产者,有钱人;富国;〈英俚〉欺骗,诈骗

第三人称单数: has 现在分词: having 过去式: had 过去分词: had

例句:

When I met her, she had just returned from a job interview 

我遇见她时,她刚参加完一场求职面试回来。

You haven't sent her away, have you? 

你还没有把她送走,是吗?

热心网友 时间:2022-04-08 13:40

付费内容限时免费查看回答您好,很高兴为你解答问题,本题由小天老师为你解答,小天老师有十年工作经验,竭诚为你服务,您的问题我已经看到了,我正在为你整理答案,请稍等一会儿,3分钟之内回复你,不要着急哦。

      主语为第三人称单数时用has,其余人称都用have。例如:主语是I,we,they时用have;主语是she,he时用has。

      作吃,喝讲。例如:I

      have a cup of tea.3.作有讲。例如:I have a new computer.

      提问这样填对吗?

      回答五个错四个

      1.is

      2.has

      3.have

      5.is

      提问好的,谢谢

      回答还有其他事没

      没有其他问题的话,我就去忙了。

      你可以点击我的头像关注我,后边有什么问题,随时可以来咨询。有什么不懂的,我都可以给你讲解。

      提问晚上,现在暂时没有

      晚上,现在暂时没有

      回答好的,记得给个赞哈,谢谢!

      提问嗯嗯

      回答

      热心网友 时间:2022-04-08 15:31

      have、had、has的用法和区别:

      1、have、had、has区别在于不同时态和不同人称之间,三个单词其实表达为一个意思。

      2、如果是一般现在时,第三人称单数的时候用has,其它(如第一人称和第二人称)用have。

      3、如果是一般过去时,全部都用had。

      4、has/have been是现在完成时,has用于第三人称单数,had been过去完成时,跟前者相比,比前者更为过去。

      拓展资料

      have

      1、Alex has already gone 

      亚历克斯已经走了。

      2、When I met her, she had just returned from a job interview 

      我遇见她时,她刚参加完一场求职面试回来。

      3、You haven't sent her away, have you? 

      你还没有把她送走,是吗?

      4、He arrived in San Francisco, having left New Jersey on January 19th 

      1月19日离开新泽西后,他到了旧金山。

      5、I went out and had a walk around 

      我出去在周围散了一会儿步。

      had

      1、Had he succeeded, he would have acquired a monopoly 

      要是他当时成功了,他就会取得垄断地位。

      2、If your customer thinks he's been had, you have to make him happy. 

      要是顾客感觉自己当了冤大头,你就得设法让他消气。

      3、Unless she loses some weight, she's had it 

      除非她减点儿肥,否则她就没戏了。

      4、I've had it. Let's call it a day 

      我受不了了。今天就到这儿吧。

      5、Had I known what the problem was, we could have addressed it. 

      如果我当时知道问题出在哪里,我们就可以设法解决了。

      热心网友 时间:2022-04-08 17:39

      have had has这三个单词中文意思都是“拥有(表示一种状态)”的意思,但英文上用法有些区别,具体如下:
      1.在英语句子中,若句子的时态是一般现在时,则have/has适用于这种情况下,其中当主语是第一人称,第二人称,第三人称复数(I,They,have)时,使用have,当主语时第三人称单数(she/he),则使用has,如下列例句:
      I/You/They have a big apple.我/你/他们 有一个大苹果。

      She/He has a small apple.她/他有一个小苹果。
      2.若句子的时态时一般过去式,则无论人称是哪一种,都是用had。如下列例句:
      I/You/They/She/He had a car. 我/你/他们/她/他过去有辆车。

      3.若句子是完成式的形式。则has/have been是表示现在完成时,has用于第三人称单数,had been则用于过去完成时。如例句:
      I have been studying English for ten years.我一直在学英语,已达十年之久。

      热心网友 时间:2022-04-08 20:04

      have和has在用于英语表达动词“有”的含义时,前者使用于第一人称、第二人称和各人称复数,has用于第三人称单数,同时它们也作为完成时态的助动词存在,其用法和做实义动词“有”的规则也是一样的.

      had是have的过去时态,和完成时。

      助动词have的用法
      1)have +过去分词,构成完成时态,例如:
      He has left for London. 他已去了伦敦。
      By the end of last month, they had finished half of their work.
      上月未为止,他们已经完成工作的一半。

      2)have + been +现在分词,构成完成进行时,例如:
      I have been studying English for ten years.
      我一直在学英语,已达十年之久。

      3)have+been +过去分词,构成完成式被动语态,例如:
      English has been taught in China for many years.中国教英语已经多年。

      动词have/has表示"有"时,它通常有三个含义:
      A.表示"某人(在物质上的)所有."这种情况下不能用there be替换.如:
      I have a new watch. 我有一块新表.
      He has a good friend. 他有一个好朋友.
      B.表示"某人或动物(在身体上的)长有".这种情况也不能用there be替换.
      如:
      She has blue eyes. 她的眼睛是蓝色的.
      A horse has two ears. 马有两只耳朵.
      C.表示"某物体(在结构上的)装有".这种情况可以用there be替换.如:
      A clock has a round face.= There is a round face on a clock.
      钟上装有一个圆型的钟盘.
      That room has only two windows.= There are two windows in that room.
      那个房间仅装有两扇窗户.
      The school has 14 classes. = There are 14 classes in the school.
      那个学校有14个班级.
      D.另外,表示"某人手中有某物"时,也用have/has.例如:
      Mary has a glass of water in her hand. 玛丽手中端着一玻璃杯水.

      热心网友 时间:2022-04-08 22:45

      has用在第三人称单数形式(能转换成it的人称形式)中;have用在第一人称和第二人称中;如果一个句子中有does(或did)的话,has变为have,does就相当于一个还原器。 例句: has:He has a bag.have:I have:I have a pen.我有一知钢笔..而Had复数 单数 也没要求人称 ,只要过去式就可以了!

      热心网友 时间:2022-04-09 01:43

      如果是一般现在时:第三人称单数的时候用has,其它用have
      如果是一般过去时:全部都用had

      热心网友 时间:2022-04-09 08:29

      Õ_Õ不

      热心网友 时间:2022-04-09 12:17

      has和have都表示有,但用法不同。
      has用在第三人称单数形式(能转换成it的人称形式)中;have用在第一人称和第二人称中;如果一个句子中有does(或did)的话,has变为have,does就相当于一个还原器。
      例句:
      has:He has a bag.他有一个书包。
      have:I have a pen.我有一知钢笔。
      Do you have a book?你有一本书吗?
      关于does的:Does he have a notebook?他有一个笔记本吗?
      She doesn't have a computer.她没有一个电脑。
      还有姓名加have
      were
      A young man and a young woman were sitting behind me.
      (一名年轻男子和一名年轻女子坐在我的后面.)

      在这个句子中, a young man 和 a young woman 是两个人, 所以便组成一个复数的主语. 如果要用一个代名词来代替 a young man and a young woman 的话, 便会用'they'.

      之所以后面用的是'were'是因为主语(they)是复数, 而且是过去式. (如果是现在式的话, 便会用'are')
      has had
      过去完成时(past perfect tense)表示在过去某一时间或动作以前已经完成了的动作。简言之,过去完成时所表示的时间就是“过去的过去”。过去完成时由助动词had + 过去分词构成。
      过去完成时的用法
      1)过去完成时表示在过去某一时间或动作以前业已完成的动作。这个过去的时间可以用by,before等介词短语或一个时间状语从句来表示。如:
      By the end of last week we had learned ten lessons.到上周末为止,我们已经学了十课书。
      He had learned some English before he came to the institute.他来学院之前学过一些英语。
      I didn’t go to the film because I had seen it twice.我没去看电影,因为这片子我已看过两次了。
      When I had gone over my lessons I took a rest.我复习完功课之后,休息了一会儿。
      I gave my little sister the flowers that I had bought for her.我把给妹妹买的花送给她。
      In the exhibition he saw many oil paintings that he had never seen before.他在展览厅里见到许多过去从未见过的油画。
      2)过去完成时可以表示由过去某一时间开始,一直延续到过去另一时间的动作,常和for(有时可以省去)或since构成的短语或since引导的从句连用。如:
      It rained yesterday after it had been dry for many months.在天旱了好几个月之后,昨天下雨了。
      By the I read his new book, I had known him for a long time.到我读他的新书时,我早就知道他了。
      He said that great Changes had taken place in his hometown since,1980. 他说7980年以来他的家乡大变样了。
      [注]当一个由when,before,after,as soon as等连词引导的从句所表示的动作和主句的动作紧接时,两个动作均可用“一般过去时”来表示。如:
      We had breakfast after we did morning exercises.做完早操后,我们吃早饭。
      When I finished supper,I took a walk.我晚饭后就去散步。
      The train started to move just before he reached the platform.他到月台时火车刚开走。
      They started ploughing as soon as they got to the fields.他们一到地里就开始耕地。

      将来完成时的基本概念和形式
      将来完成时(future perfect tense)表示在将来某一时间之前所完成的动作。它的形式由shall(第一人称)或will(第二、三人称)加have再加过去分词所构成。美国英语一律用will。
      将来完成时的用法
      将来完成时表示在将来某一时间以前已经完成的动作。如:
      By the end of this week, I shall have finished the book.到本周末,我将读完这本书。
      By this time tomorrow they will have repaired the machine.明天这时候,他们将修好这台机器。
      The children will have gone to sleep by the time We get home.到我们回家时,孩子们将已睡了。
      When you come tonight at eight o'clock,I shall have written my paper.你今晚八点钟来时,我将会写完文章了。
      By next year our teacher will have taught English for twenty years.到明年我们的老师将已教二十年英语了。

      [英语语法手册]完成进行时态
      过去将来完成时
      过去将来完成时(past future perfect tense)表示在过去将来某一时间以前已经完成的动作。它的形式由should(第一人称)或Would(第二、三人称)加have再加过去分词构成。美国英语一律用Would。
      用法举例:
      He said he would have paid me back the money by the end of the week.他说将在周末前还我钱。
      We told him that we should have returned to the camp by four o'clock.我们告诉他我们将于四点前回营地。
      I hoped she would have finished the work before I got back.我希望她在我回来之前做完那活儿。

      种类
      完成进行时有现在完成进行时、过去完成进行时、将来完成进行时和过去将来完成进行时四种。

      现在完成进行时的用法
      1)表示动作从过去某一时间开始一直延续到现在。现在这个动作可能已经终止,也可能仍然在进行着。如:
      I have been waiting for you for two hours.我等了你两个小刊(动作不再延续下去)
      It has been raining for three hours.雨已经下了三小时了。(动作可能延续)
      He has been working on the paper all day.他整天都在写论文(动作是否延续下去,由上下文决定。)
      How long have you been learning English? ——I have been learning English for two years.你英语学多久了?——我们学了两年了。(动作可能延续)
      Why are you so dirty - I've been playing football.你身上怎么这样脏?——我刚才踢足球了。(动作不再延续下去)
      2)有些不能用现在进行时态的动词,如be,have like,love,know,see,hesr等,同样也不能用现在完成进行时,而只能用现在完成时。如:
      She has been ill for a long time.她已经病了好久了。
      I have not seen you for ages.我好久没有见到你了。

      现在完成进行时和现在完成时的比较
      1)现在完成时所表示的动作,到现在为止已经完成;现在完成进行时往往表示动作仍然继续下去。如:
      I have been reading Lu Xun this week.本周我一直在读鲁迅的著作。(我仍然在读。)
      I have read A Madman is Diary this week.我本周读了《狂人日记》。(我本周开始读而且已经读完它了。)
      I have read The story of Ah Q before.我以前读过《阿Q正传》。(过去经历)
      2)现在完成时强调动作的最后结果;现在完成进行时则强调动作的直接结果。如:
      Now we have cleaned the room,we can move the things in.房间已打扫过了,我们可以把东西搬进去了。(强调最终结果)You look so tired. What have you been doing? 你看来很累的样子,你干什么来着?(强调直接结果)

      过去完成进行时(past perfect continuous tense)
      1)过去完成进行时的形式一律为had been + 现在分词,无人称和数的区别。
      2)过去完成进行时的用法 过去完成进行时表示动作在过去某一时间之前开始并延续到过去这个时间,这一动作可能还在进行,也可能已经停止。如:
      He told me that he had been waiting for me for two hours.他对我说他等了我两小时。(动作不再延续)
      The baby had been crying for fifteen minutes when her mother came in.妈妈进来时,婴儿一直哭了十五分钟。(动作可能还在进行)
      It seemed to her that the boys had been shouting for a long time.她似乎觉得这些男孩一直叫喊了很久。(动作可能还在进行)
      The teacher had been teaching for forty years by the time he retired,这位教师退休前一直教了四十年的书。(动作不再进行

      'is'是用於单数主语及现在式, 单数主语及过去式是用'was'. 汇众动漫学院 http://sjza.gamfe.com/
      声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
      E-MAIL:11247931@qq.com
      Top